Skip to content
Codewilds

Lesson 21 of 29 · Layout with Flexbox

Boss: Build a Flexbox Navbar and Card Layout

Boss battlehard100 XP2 min read

The Tangled Vines blocks the way. Every test you pass deals damage — pass them all to defeat it and claim a loot chest.

Deep in the Painted Cliffs, the village of Vinewood has a problem: the Tangled Vines have crept over its website, and every logo, link and card is knotted into one long, untidy column. Only one blade is sharp enough to cut them loose, and it's called flexbox.

Battle plan

This fight uses everything from the chapter:

  • display: flex turns a parent into a flex container and lines its children up in a row.
  • justify-content: space-between pushes the first and last items to opposite ends: the classic navbar layout.
  • align-items: center centres the items on the cross axis, so a tall logo and short links line up neatly.
  • gap adds space between the items.
  • flex-wrap: wrap on the container plus flex: 1 1 <basis> on the items gives a card row that wraps and fills every line.

Flex containers can be nested. A flex item, like the logo, can also be a flex container for its own children:

.navbar { display: flex; } /* the logo and the nav are its flex items */
.logo   { display: flex; } /* the icon and the name are its flex items */

Assignment

Untangle the Vinewood page. Write your CSS below the comment in the <style> element:

  1. Navbar: make .navbar a flex container with the logo at the left end and the links at the right end (justify-content: space-between), both vertically centred (align-items: center).
  2. Logo: make .logo a flex container, so the icon and the name sit side by side, vertically centred, with an 8px gap.
  3. Links: make .links a flex container with a 24px gap between the links.
  4. Card row: make .cards a flex container that wraps (flex-wrap: wrap), with a 20px gap.
  5. Cards: give every .card flex: 1 1 250px. On the 1024px-wide test page, three cards share each row and grow to fill it; on a 600px screen, two cards share a row.

Each passing test lands a blow on the Tangled Vines. Make all ten pass to free Vinewood.

Premium lesson

Unlock the full Learn HTML & CSS course

  • All 29 lessons, bosses and quizzes — lifetime access
  • One payment of $35, no subscription
  • Finish within 30 days and claim $10.50 (30%) back
Play the 7 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.

Keep learning

Need a quick reminder? The HTML & CSS cheat sheet has every topic of Learn HTML & CSS on one page.

Lesson last updated on .

Write code ↓
HTML & CSS+100 XP

Lesson 21 is part of the full course. The first 7 lessons are free.

Premium lesson

Unlock the full Learn HTML & CSS course

  • All 29 lessons, bosses and quizzes — lifetime access
  • One payment of $35, no subscription
  • Finish within 30 days and claim $10.50 (30%) back
Play the 7 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.