Put boxes side by side in a row with Flexbox, and find out that it goes on the box that holds them.
Almost every menu bar, toolbar and row of cards on the web is a Flexbox row.
So far, boxes stack down the page. Flexbox lines them up in a row.
Make your prediction first. Help opens once you've locked it in.
<style>
ul {
display: flex;
list-style: none;
}
li {
margin-right: 24px;
}
</style>
<ul>
<li><a href="https://example.com/home">Home</a></li>
<li><a href="https://example.com/events">Events</a></li>
<li><a href="https://example.com/join">Join</a></li>
</ul>
display: flex is new. list-style: none removes a list's bullets, and the margin-right on each li keeps the words apart. Read the code. How will the menu items be placed?
Compare with your prediction. Then delete the display: flex; line to see the menu stack again, and put it back.
| Code | What it does | Why |
|---|---|---|
ul { display: flex; } |
Puts the ul's children in a row |
The box that holds the items is the parent, and its boxes inside are its children. Flex goes on the parent, and the children line up |
the three li |
Sit side by side | They are the parent's children. Without display: flex they are block boxes, and block boxes start a new line |
list-style: none; |
Removes the bullets | Not Flexbox: real menus have no bullets, so it is a tidy-up on the list |
li { margin-right: 24px; } |
Keeps the words apart | A margin on each item. Items in a row touch otherwise |
<style>
ul {
display: flex;
list-style: none;
}
li {
margin-right: 24px;
}
</style>
<ul>
<li><a href="https://example.com/home">Home</a></li>
<li><a href="https://example.com/events">Events</a></li>
<li><a href="https://example.com/join">Join</a></li>
</ul>
The picture shows a row of cards: the div holds them, and each card holds a picture and a name.
<style>
.cards {
background-color: aliceblue;
}
.card {
padding: 12px;
border: 2px solid teal;
margin: 8px;
}
</style>
<div class="cards">
<div class="card">
<img src="trophy.svg" alt="Trophy" width="50">
<p>Owls</p>
</div>
<div class="card">
<img src="medal.svg" alt="Medal" width="50">
<p>Hawks</p>
</div>
<div class="card">
<img src="star.svg" alt="Star" width="50">
<p>Kestrels</p>
</div>
</div>

Look at the cards.

This should be a row.
Think about how the boxes nest.
This menu should be a row, but the items still stack, and there is no error. Click the line that picks the wrong box.
Put the menu items side by side.
Flexbox goes on the parent, the box that holds the items. Which rule is that?
Add display: flex; to the .menu rule.

The three cards are stacked. Put them in a row.
The cards are inside a div with the class cards. That div is the parent.
Write a new .cards rule and put display: flex; first in it.

A list has space of its own around it. Remove it from the menu with margin: 0; and padding: 0;.
The list has its own space around it. Which two box properties would remove it? Set them in the .menu rule.

Put the menu in a row.
This ticks when your page has all of the above.
Put the cards in a row.
This ticks when your page has all of the above.
Remove the menu's own spacing.
This ticks when your page has all of the above.
The header holds the title and the menu row. The story below has a link of its own.
<style>
header {
background-color: lightblue;
}
.menu {
display: flex;
list-style: none;
}
.menu li {
margin-right: 24px;
}
</style>
<header>
<h1>Robotics Club</h1>
<nav>
<ul class="menu">
<li><a href="https://example.com/home">Home</a></li>
<li><a href="https://example.com/events">Events</a></li>
<li><a href="https://example.com/join">Join</a></li>
</ul>
</nav>
</header>
<p>We meet every Tuesday. <a href="https://example.com/map">Find the STEM lab</a>.</p>
Make the top of the club page: a <header> with the club name and, under it, a <nav> holding a list of at least three links. Put the links in a row, without bullets.
A menu is a list of links inside a <nav>. Which box holds the items?
Build a <header> with an <h1> and a <nav> holding a <ul> of links, then write a rule for the ul that starts with display: flex;.
Add list-style: none;, and a margin on each li so the words do not touch.

Put the club menu in a row inside the header.
This ticks when your page has all of the above.
Students put boxes in a row with display flex, and find out that it goes on the box that holds them, not on the items. About 45 minutes.
Open the teacher guide: answers, solutions, slides and a worksheet.
Read the unit primer "Layout and components in 5 minutes", then do the Make task yourself.
The one idea of the lesson: display: flex; goes on the parent (the box that holds the items), and its children line up in a row. Only the direct children line up. Spacing, centring and wrapping are the next lessons, so here the space between items is a margin on each item. list-style: none; is not Flexbox: it removes a list's bullets, which every real menu does.
display: flex goes on the parent, not the items. When the row doesn't appear, ask which box holds the items before saying anything else.
Stretch: Make the cards a row too, with a picture in each, and predict what happens if a card has display flex as well.
Support: Give students the Modify starter and do the first task together, saying out loud: the menu is the parent, so display flex goes in .menu.
Next lesson spaces the row out: gap, justify-content and align-items, so the club name sits left and the menu right. Class idea: find three websites and sketch which parts are Flexbox rows (menus, toolbars, rows of cards).