Students let a flex row wrap with flex-wrap, share each line with flex: 1 and set a min-width, and find out that a fixed width does not change with the screen.
Load these into Waypoints Prepare: choose Load URL and paste the copied address, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
Predict and Run 10 min · Investigate 12 min · Mix it up 3 min · Modify 7 min · Make 8 min
Do the Make task yourself in the playground (about 5 minutes).
A flex row keeps all its items in one line unless it is told it may wrap. flex-wrap: wrap on the row allows new lines. flex: 1 on the items makes them share the spare room on their line. min-width is the narrowest an item may be: once a line cannot fit another item at that width, the item drops to the next line. Together they make a layout that fits a phone and a laptop with no separate versions.
The preview pane is narrow, so students do not need to resize the browser. They change the number of cards or the min-width and see the same effect a screen of a different width would give.
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
With your partner, say what the preview does with six cards that cannot all fit. Hold up 1, 2, 3 or 4 fingers for the option you chose.
Take a vote before running. Ask someone who chose the first option what tells the row it may start a new line. The idea to land: it has to be allowed.
On a strip of paper, draw a line 450px wide at a scale of your choice. Cut out six cards at 140px and fit as many as you can with 12px gaps. Then try 220px cards.
Check that students count gaps as well as cards. Ask what changes on a phone-width strip.
Believing the browser moves items down by itself. Ask what the row has been told about wrapping before saying.
| What you will see | A question to ask | The fix |
|---|---|---|
| The cards run off the edge and do not wrap. | Which rule has flex-wrap? | Put flex-wrap wrap in the rule of the box that holds the cards, the same rule as display flex. |
| The cards are thin, with words broken into pieces. | What stops a card getting narrower? | Add a min-width to the card rule. A card that would be narrower drops to the next line. |
| One card stretches across a whole line by itself. | How many cards are on that line? | With flex 1 a lone card on a line grows to fill it. That is expected. A smaller min-width puts more cards on each line. |
One possible solution for each task. Other correct programs are fine.
<style>
.gallery {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.item {
flex: 1;
min-width: 120px;
border: 2px solid teal;
padding: 8px;
}
</style>
<div class="gallery">
<div class="item">Robot building on Tuesdays</div>
<div class="item">Coding games at lunch</div>
<div class="item">Drone flying on the oval</div>
<div class="item">Design a logo this term</div>
<div class="item">Music for the robots</div>
<div class="item">Chess for the clever</div>
</div>
<style>
.gallery {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.item {
flex: 1;
min-width: 180px;
border: 2px solid teal;
padding: 8px;
}
</style>
<div class="gallery">
<div class="item">Robot building on Tuesdays</div>
<div class="item">Coding games at lunch</div>
<div class="item">Drone flying on the oval</div>
<div class="item">Design a logo this term</div>
<div class="item">Music for the robots</div>
<div class="item">Chess for the clever</div>
</div>
<style>
.gallery {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.item {
flex: 1;
min-width: 120px;
border: 1px solid gray;
padding: 6px;
}
</style>
<h1>Our club's year</h1>
<div class="gallery">
<div class="item"><img src="trophy.svg" alt="Trophy" width="80"><p>Trophy</p></div>
<div class="item"><img src="medal.svg" alt="Medal" width="80"><p>Medal</p></div>
<div class="item"><img src="book.svg" alt="Book" width="80"><p>Book</p></div>
<div class="item"><img src="ball.svg" alt="Ball" width="80"><p>Ball</p></div>
<div class="item"><img src="star.svg" alt="Star" width="80"><p>Star</p></div>
<div class="item"><img src="music.svg" alt="Music" width="80"><p>Music</p></div>
</div>
Stretch: Give the gallery a width of 300px, then 600px, and write down how many cards fit on a line each time. Explain the numbers with min-width and gap.
Support: Give students the Run page and ask them only to add the wrap line and to change the number of cards. Tell them what each change does to the cards on a line.
A gallery uses flex: 1 and min-width: 150px. Why does it show four cards on a line on a laptop but one on a phone?
A line holds as many 150px cards as fit, and flex: 1 stretches them to fill it. A phone only has room for one, so the others wrap.
Next lesson uses a wrapping row for a hero and a row of cards, and shows that one rule can style any number of copies. Class idea: open a school website and drag the window narrower; ask which parts wrap.