Lesson 2 Lab — A Card Grid, and Flexbox Froggy¶
Reinforce flexbox two ways: build a wrapping card grid from the cards you styled in Lesson 1, and drill the core properties with Flexbox Froggy. Same plain-file setup as the guide — no framework. Refer back to the guide for the flexbox properties.
Part A — a wrapping card grid¶
In Lesson 1 you built a single card. A real list page shows many cards that wrap
across the page as it narrows — a flex container with flex-wrap.
- In
css-fundamentals/, createcard-grid.html(Emmet!+ Tab, thenlink:css) +card-grid.css, with* { box-sizing: border-box; }at the top. Open it with Live Server. - Bring over your Menu Item card CSS from Lesson 1 (the
.card,.name,.price,.badgerules). - In the HTML, wrap several cards (4–6, different menu items) in a container:
<section class="grid"> …cards… </section>(Emmet:section.gridfor the container,div.cardfor each card). - Make the container a wrapping flex row:
- Save and resize the window — the cards should reflow onto fewer/more per row
as the width changes. That reflow is
flex-wrapdoing the work of a grid, with norow/colanywhere.
Part B — a header row above the grid¶
- Above the grid, add the header row from the guide (section 4): an
<h2>"Menu" on the left and a "Add Item" button on the right, usingdisplay: flex; justify-content: space-between; align-items: center.
Part C — Flexbox Froggy¶
- Play Flexbox Froggy and complete roughly the first 12–15 levels:
flexboxfroggy.com. Those levels drill
justify-content,align-items, andflex-direction— the exact properties from the guide. Stop once the later levels move past what we've covered; you don't need the whole game.
Verify in the browser¶
Browser checks work the same as the guide — section 7. With card-grid.html open in
Live Server:
- Confirm the cards sit in a wrapping row with even
gapspacing, and that they reflow when you resize the window. - Confirm the header row has the title left and the button right, vertically aligned.
- Open DevTools (F12), select
.grid, click itsflexoverlay badge, and confirm the main axis runs across and items wrap to new lines. - Check the Console for a failed stylesheet load if nothing is styled.
A wrapping card grid and a header row are the two layouts you'll build on every list page this pass — next lesson you'll make them with Bootstrap's flex utilities instead of hand-written CSS, but the layout is identical.
Stretch challenges¶
Optional — for when you finish early. Not needed for the capstone. [Reinforce] builds on what you just did; [Reach] goes past the guide and needs some research.
- Center a lonely card — [Reinforce] — in a container with a single card, use
justify-content: centerandalign-items: center(give the container aheight) to center it both ways — the Sign In page centering you'll meet later. - Column on narrow, row on wide — [Reinforce] — build a small two-box layout and
switch its
flex-directionfromrowtocolumnby hand; watch the main axis flip andjustify-content/align-itemsswap which way they push. - Nudge one item — [Reach] — give one flex item
align-selfto override the container'salign-itemsfor just that child. Not covered in the guide — research it: align-self (MDN). - Push the last item away — [Reach] — in a row of items, give one item
margin-left: autoand watch it (and everything after it) shove to the far end — a handy flexbox trick. Research: Aligning items in a flex container → auto margins (MDN).
Layout in this course is flexbox only — we deliberately don't use CSS Grid. You may meet Grid on the job; here, everything you need for a card grid is
flex-wrap+gap.
Finished these and want more? See stretch-html-css-challenges.md for bigger challenges that span the whole HTML/CSS pass.