Learn HTML and CSS: Grid or flexbox, which when
Grid or flexbox
Gus's grandson says "everyone uses grid these days". So should the menu go in a grid too? Not necessarily: every tool has its own job, and a good page uses both.
Two tools
Flexbox works in one direction: a row or a column. The items decide how wide they are, and the container shares out what's left. Ideal for a menu, a row of buttons or a header with a logo and a menu.
Grid works in two directions at once: rows and columns. You draw the tracks, and the items fall into them, neatly under each other, even when their content differs. Ideal for a site plan, a set of cards or the layout of a whole page.
On the page the menu stands side by side with flexbox, and the field in columns with grid. Often one sits inside the other.
nav { display: flex; flex-wrap: wrap; gap: 4px;}.field { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;}Try it yourself
Put the links of the menu side by side with flexbox, and lay the field out in three equally wide columns with grid.
/* Your CSS goes here. */<!DOCTYPE html><html lang="en"><head> <title>The Lazy Hammock</title> <link rel="stylesheet" href="basis.css"> <link rel="stylesheet" href="style.css"></head><body> <header> <img src="tent.svg" alt="" width="40" height="40"> <h1>The Lazy Hammock</h1> <nav> <a href="index.html">Home</a> <a href="pitches.html">Pitches</a> <a href="prices.html">Prices</a> <a href="book.html">Book</a> </nav> </header> <main> <p class="slogan">Camping among the pines in Bala. Peace and quiet guaranteed.</p> <section class="field"> <div class="pitch tent">Tent</div> <div class="pitch caravan">Caravan</div> <div class="pitch camper">Camper</div> <div class="pitch cabin">Cabin</div> <div class="pitch tent">Tent</div> <div class="pitch hammock">Hammock</div> </section> <section class="cards"> <article class="card"> <h2>Showers</h2> <p>Hot showers and a washing-up area, open all day.</p> </article> <article class="card"> <h2>Shop</h2> <p>Fresh bread every morning from 8 am.</p> </article> <article class="card"> <h2>Lake</h2> <p>Swimming in summer, fishing all year round.</p> </article> </section> </main> <footer> <p>1 Hammock Lane, Bala LL23 7SR</p> </footer></body></html>body { margin: 0; font-family: system-ui, sans-serif; background: #f5f2e8; color: #1f2a22;}header { padding: 12px 16px; background: #2d4a3a; color: #ffffff;}header h1 { margin: 0; font-size: 1.5rem;}nav a { padding: 6px 10px; border-radius: 999px; color: #ffffff; text-decoration: none;}main { padding: 0 16px 24px;}.slogan { margin: 16px 0 0;}.field { margin: 16px 0; padding: 9px; border-radius: 18px; background-color: #bcd6a0; background-image: repeating-linear-gradient(90deg, rgb(255 255 255 / 0.13) 0 20px, transparent 20px 40px); box-shadow: inset 0 0 0 1px rgb(45 74 58 / 0.16);}/* A little tent, caravan or cabin on every pitch: only for the look. */.pitch { position: relative; margin: 3px; padding: 27px 4px 9px; border-radius: 12px; background: #fffdf6; box-shadow: 0 1px 2px rgb(31 42 34 / 0.12), 0 6px 14px -8px rgb(31 42 34 / 0.4); font-size: 0.875rem; font-weight: 700; line-height: 1.25; text-align: center;}.pitch::before { content: ""; position: absolute; top: 9px; left: 50%; width: 16px; height: 12px; margin-left: -8px; background: #e07a3f; clip-path: polygon(50% 0, 100% 100%, 0 100%);}.caravan::before { width: 18px; margin-left: -9px; border-radius: 5px 5px 3px 3px; background: #3d8c95; clip-path: none;}.camper::before { width: 20px; margin-left: -10px; background: #4f7cac; clip-path: polygon(0 15%, 68% 15%, 100% 55%, 100% 100%, 0 100%);}.cabin::before { background: #9c6b3f; clip-path: polygon(50% 0, 100% 45%, 100% 100%, 0 100%, 0 45%);}.hammock::before { top: 11px; width: 20px; height: 7px; margin-left: -10px; border-bottom: 3px solid #c99a2e; border-radius: 0 0 10px 10px; background: none; clip-path: none;}.reception::before { width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #2d4a3a; clip-path: none;}.lake::before { top: 10px; width: 24px; height: 11px; margin-left: -12px; border-radius: 50%; background: #5fa8d3; clip-path: none;}.playground::before { width: 18px; margin-left: -9px; background: #d1495b; clip-path: polygon(50% 0, 100% 100%, 82% 100%, 50% 32%, 18% 100%, 0 100%);}aside { padding: 12px 16px; background: #e4ecd6;}aside h2 { margin: 4px 0 8px; font-size: 1.05rem;}.card { padding: 4px 16px; border-radius: 12px; background: #ffffff; box-shadow: 0 1px 2px rgb(31 42 34 / 0.08);}.card h2 { font-size: 1.15rem;}footer { padding: 12px 16px; background: #2d4a3a; color: #ffffff;}Ready for more?
The full lesson has 5 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson