Learn HTML and CSS: Box-sizing
Box-sizing
Joanne gave the notice `width: 100%` and some padding. Now it sticks out on the right of the page, and on a phone you have to scroll sideways to read it.
What the width is about
By default width is only about the content. The padding and the border are added on top. So width: 100% with 24px of padding left and right is 48px wider than the space there is: the box sticks out.
With box-sizing: border-box, width is about the whole box, up to and including the border. The padding then comes off the content, and width: 100% fits exactly.
That's why many sites put * { box-sizing: border-box; } at the top of their CSS. The asterisk * picks every element.
.notice { width: 100%; padding: 12px 24px;}Try it yourself
At the top, add the rule that gives every element border-box. Then give the cards width: 100% and 16px of padding.
/* Your CSS goes here. */<!DOCTYPE html><html lang="en"> <head> <title>The Steep Wall climbing centre</title> <link rel="stylesheet" href="basis.css"> <link rel="stylesheet" href="style.css"> </head> <body> <header> <img src="greep.svg" alt="" width="40" height="40"> <h1>The Steep Wall</h1> <p class="slogan">Climbing centre in Ilkley</p> <nav> <a href="index.html">Home</a> <a href="routes.html">Routes</a> <a href="prices.html">Prices</a> <a href="lessons.html">Lessons</a> </nav> </header> <main> <p class="notice">We're closed on Saturday 12 April for a competition.</p> <section class="cards"> <article class="card"> <h2>Day pass</h2> <p class="price">£14</p> <p>Climb all day, for as long as your arms hold out.</p> <a class="button" href="buy.html">Buy</a> </article> <article class="card"> <h2>Ten-visit pass</h2> <p class="price">£120</p> <p>Ten visits, valid for a year.</p> <a class="button" href="buy.html">Buy</a> </article> </section> <section class="news"> <h2>News</h2> <p>There are twelve new routes in the bouldering room, from green to black.</p> <p>There's a beginners' class every Tuesday. We'll lend you climbing shoes.</p> <p>On Wednesday afternoons the youth club climbs. Feel free to come and watch.</p> </section> </main> <footer> <p>7 Handhold Lane, Ilkley</p> </footer> </body></html>body { margin: 0; font-family: system-ui, sans-serif; background: #eef3ee; color: #1f2a24;}header { padding: 16px; background: #2d6a4f; color: #ffffff;}header h1 { margin: 4px 0 0;}.slogan { margin: 0 0 8px;}nav a { color: #ffffff;}main { padding: 0 16px 24px;}.notice { background-color: #ffe8d6;}.card { padding: 0 16px; background: #ffffff;}.price { font-size: 1.5rem; font-weight: bold;}.button { background-color: #e76f51; color: #ffffff; text-decoration: none;}.news { background: #ffffff;}footer { padding: 12px 16px; background: #1b4332; 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