Learn HTML and CSS: Rows and space in a grid
Rows and gap
Gus wants grass between the pitches. "Nobody likes pitching their tent against the neighbours' caravan," he says. And the cabins could do with a bit more room than a little tent.
Rows and space
You don't have to draw rows: the grid makes as many as it needs, each as tall as the tallest pitch in it. If you want a fixed height, you give it with grid-template-rows, just like the width of the columns.
With gap you put space between the rows and between the columns, never along the edge. gap: 12px counts for both. With two values the space between the rows comes first, then the space between the columns. Separately works too, with row-gap and column-gap.
On the page the first row is 90px tall and the second 60px, with 12px of grass between all the pitches.
.field { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: 90px 60px; gap: 12px;}Try it yourself
Lay the field out in three equally wide columns, with 12px of space between the pitches.
/* 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