Learn HTML and CSS: Display
Display
Joanne gave the buttons padding, but now they run over the text above. And the menu links refuse to take a width. It's not the padding, it's the kind of box.
Block, inline and in between
With display you choose how a box behaves. A block starts on a new line and takes the full width, like <p>, <h2>, <div> and <section>.
An inline element sits in the line between the words, like <a>, <span> and <strong>. It ignores a width or height, and padding and margin above and below don't push the lines aside.
inline-block is the best of both: it sits in the line, but it's a real box, with a width and padding that count. And display: none makes an element disappear completely.
.button { display: inline-block; padding: 8px 16px; margin-top: 8px;}Try it yourself
Make the notice disappear completely, and turn the menu links into little buttons: inline-block, with 8px 12px 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 6 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson