I want to present ads in a way that smoothly places them (mainly) next to each other. But when they enter next row, they should be placed directly underneath the above one. See picture.
Above is what code gives me. Below is what I want.
Children need to flex wrap while aligning at flex start, but won't let me
CSS:
.annonser {
border: 1px solid white;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
gap: 15px;
padding: 10px;
}
.annons {
align-items: flex-start;
width: 245px;
}
Annonser: Parent div Annons: Children
Google suggests align-items: flex-start should fix the problem, but I can still see visually that children allign their "height" to the tallest child.
I'm very grateful for any help!
Edit: Setting aling-items: flex-start to parent provides the same result...
.annonser {
border: 1px solid white;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: space-evenly;
gap: 15px;
padding: 10px;
}
.annons {
align-items: flex-start;
width: 245px;
}
<div class="annonser">
<div class="annons">
<div class="1">
<p>Header</p>
<p>Text</p>
<p>Price</p>
<p>Recommended</p>
</div>
</div>
<div class="annons">
<div class="2">
<p>Header</p>
<p>Text Text Text Text Text Text Text </p>
<p>Price</p>
</div>
<div class="2">
<p>Header</p>
<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </p>
<p>Price</p>
</div>
<div class="2">
<p>Header</p>
<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </p>
<p>Price</p>
</div>
<div class="2">
<p>Header</p>
<p>Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text </p>
<p>Price</p>
</div>
<div class="2">
<p>Header</p>
<p>Text</p>
<p>Price</p>
</div>
</div>
</div>
Edit 2
I inserted a snippet. However I'm working with asp.net MVC, so my ads are autogenerated from a DB. Should act the same though. Instead of generating ads I've made a bunch to represent them the same way. The first type is "more important" but ignore the grandchildren-classes in the snippet.