I am trying to build a "card" within a ul li
list. This cards should be responsive. Therefore my core idea was to use CSS Flexbox
. I have started a pen at codepen.io but struggling now for days to achieve this. Why cant i align easily these divs with flexbox?
This is how it should look like:
This is the pen:
https://codepen.io/bogazci/pen/WNayNXb?editors=1100
HTML
<ul class="packs-list">
<a href="#">
<li class="pack">
<div class="pack-sku">B01-102 102<br>ordered on 14th may 23</div>
<div class="pack-card">
<h2 class="pack-title">Customer Engagement</h2>
<div class="pack-description">This is the descriptin for the.</div>
<div class="pack-information">This item contains <b>2123</b> elements in <b>231</b> containers.</div>
</div>
</li>
</a>
</ul>
CSS
.pack-sku {
background-color: red;
white-space: nowrap;
transform: rotate(-90deg);
}
.pack-card {
background-color: brown;
}
.pack {
background-color: green;
width: 100%;
}
.packs-list {
background-color: yellow;
}
ul {
display: flex;
list-style-type: none;
list-style-position: inside;
margin:0;
padding:0;
}
li {
display: flex;
margin:0;
padding:0;
}
.pack-card {
display: flex;
}
2
Answers
still align based on the
height
of that elementYou can use
aspect-ratio: 1 / 1;
and negativemargin
Example :
But i suggest you to use javascript
somthing like this:
HTML
CSS
JAVASCRIPT
Syntactically an
ul
element can only containli
elements, while ali
can contain anything. I corrected the HTML to reflect that.It is not clear what you were aiming for using Flexbox Layout like you did, so I recreated your CSS starting from scratch.
The CSS is commented, so I will not repeat it here, but the trick with Flexbox Layout is to distinguish between the various column and row parent containers and which child items should be allowed/forced to grow/shrink or not.
As a bonus I added a few ‘responsiveness’ solutions and some hover effects you can fiddle with:
body { font-size }
,@media
andpack:hover
/pack:hover>a
.A Codepen you can fork…