Lesson 21 of 29 · Layout with Flexbox
Boss: Build a Flexbox Navbar and Card Layout
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: flexturns a parent into a flex container and lines its children up in a row.justify-content: space-betweenpushes the first and last items to opposite ends: the classic navbar layout.align-items: centercentres the items on the cross axis, so a tall logo and short links line up neatly.gapadds space between the items.flex-wrap: wrapon the container plusflex: 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:
- Navbar: make
.navbara 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). - Logo: make
.logoa flex container, so the icon and the name sit side by side, vertically centred, with an8pxgap. - Links: make
.linksa flex container with a24pxgap between the links. - Card row: make
.cardsa flex container that wraps (flex-wrap: wrap), with a20pxgap. - Cards: give every
.cardflex: 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
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 .