Lesson 30 of 50
cssAdvanced Flexbox – Wrapping & Alignment
9 mins
Course progress60%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 30 of 50
css9 mins
Keep these ideas in mind as you work through the lesson.
When you need multiple rows inside a Flex container, flex-wrap and the cross‑axis properties become essential.
.wrapper {
display:flex;
flex-wrap:wrap; /* allow items to flow onto new lines */
gap:1rem;
align-content:stretch; /* distributes extra space between rows */
}
.card { flex:1 1 calc(33.333% - 1rem); }
align-content only has an effect when there are multiple flex lines.stretch (default) makes rows stretch to fill the container height. center, space-between, etc. can be used for custom vertical alignment.order.item:nth-child(3) { order:-1; } /* moves the third item to the start */
Great for visual emphasis, but remember it does not affect the reading order for screen readers.
<div class="deck">
<article class="card">…</article>
<article class="card">…</article>
<article class="card">…</article>
</div>
.deck {
display:flex;
flex-wrap:wrap;
gap:1rem;
align-content:stretch; /* rows fill the container vertically */
}
.card {
flex:1 1 calc(33.333% - 1rem); /* three‑per‑row, flexible */
background:#fff; padding:1rem; border:1px solid #e0e0e0;
}
min-width with Flex Grow.card { flex:1 1 min(250px, 100%); }
If you reorder items with order, provide an ARIA live region or additional visual cue for keyboard users if the change is significant.