Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Advanced Flexbox – Wrapping | CSS Basics to Advanced lesson | BraveProgrammer
  1. Courses
  2. /
  3. CSS Basics to Advanced

Lesson 30 of 50

·css

Advanced Flexbox – Wrapping & Alignment

9 mins

Course progress60%

What you'll learn

Keep these ideas in mind as you work through the lesson.

2 points
  • `align-content` only affects the **cross‑axis** when there are **multiple flex lines**.
  • `order` does not affect accessibility order – use read‑order‑preserving HTML when possible.

When you need multiple rows inside a Flex container, flex-wrap and the cross‑axis properties become essential.

Wrapping

.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.

Reordering With 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.


Example – Responsive Card Deck with Equal Height

<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;
}

Pro Tip – Combine min-width with Flex Grow

.card { flex:1 1 min(250px, 100%); }

The card will grow to fill the row but never shrink below 250 px, preventing it from collapsing on tiny viewports.

Accessibility Reminder

If you reorder items with order, provide an ARIA live region or additional visual cue for keyboard users if the change is significant.

Make it stickPractice what you've learned1 quiz · 6 practical tests · Optional activities from CSS Basics to AdvancedBrowse activities
Previous lessonFlexbox – FundamentalsContinue to lesson 31CSS Shapes – Non‑Rectangular LayoutBack to CSS Basics to Advanced curriculum