Learn HTML and CSS: CSS rules
What CSS is
Gino slides a cup of coffee over to you. "The text is fine, my nephew says. But it's so... bare." You open style.css: it's still empty.
A rule
HTML says what is on the page, CSS says how it looks. You write CSS in rules.
A rule starts with a selector: which elements it styles. h1 finds every <h1>. Between { and } comes a property (color, the text colour), a colon, a value (purple) and a semicolon.
Look: the salon's name is purple now.
h1 { color: purple;}The semicolon
A rule can change more than one thing. Each property with its value is called a declaration, and every declaration ends with a ;.
Here the name is purple and centred (text-align: center).
Forget the ; after purple and the browser reads purple text-align: center as one strange value. It can't make sense of it, so it does neither.
h1 { color: purple; text-align: center;}Try it yourself
Your first rule of your own: make the footer (footer) grey with gray and centre it. The rest of the page stays as it is.
/* Your CSS goes here. */<!DOCTYPE html><html lang="en"> <head> <title>Snip & Curl hair salon</title> <link rel="stylesheet" href="basis.css"> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h1 id="name">Snip & Curl</h1> <p class="slogan">Hair salon in the heart of Leeds</p> </header> <main> <h2>Our prices</h2> <ul class="price-list"> <li><span class="service">Haircut</span> <span class="price">£28</span></li> <li><span class="service">Wash and blow-dry</span> <span class="price">£22</span></li> <li><span class="service">Colouring</span> <span class="price">£55</span></li> </ul> <section id="booking"> <h2>Book an appointment</h2> <p class="info">Give us a call or just pop in.</p> <a class="button" href="tel:+441134960000">Call us</a> </section> </main> <footer> <p>8 Kirkgate, Leeds</p> </footer> </body></html>body { margin: 0; padding: 0 16px;}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