Learn HTML and CSS: A page layout with grid
A whole page layout
Gus wants a new home page, with a sidebar for the weather and the opening hours of reception. "Can you lay the whole page out as neatly as the field?" With grid you can: you make a site plan of the page too.
The skeleton of a page
Grid isn't only for the pitches: you lay out the whole page with it too. Turn body into a grid and draw the areas with grid-template-areas: the header at the top, the content with a sidebar next to it, the footer at the bottom. Every block gets its area with grid-area.
The sidebar gets a fixed width, the content takes the rest with 1fr. Inside those areas you carry on with whatever fits: grid for the field, flexbox for a menu.
body { display: grid; grid-template-columns: 1fr 120px; grid-template-areas: "header header" "content sidebar" "footer footer";}header { grid-area: header; }main { grid-area: content; }aside { grid-area: sidebar; }footer { grid-area: footer; }.field { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px;}Try it yourself
Build the cards of the design: two equally wide columns with 12px of space, and the first card across the whole width.
/* 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 4 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson