Learn HTML and CSS: Backgrounds and units
Backgrounds and units
"My salon isn't white," says Gino. "Pink tiles, a green counter." The site can have some colour behind the letters too.
A background colour
color colours the letters. background-color colours the area behind them: the element's whole block.
Here the page (body) gets a soft cream, and the header (header) a petrol green bar with white letters.
If you pick a dark background, give the text a light colour. Otherwise nobody can read a thing.
body { background-color: #fff7f0;}header { background-color: #2a9d8f; color: white;}px, rem and %
A size always has a unit, right after the number, with no space. px is a fixed size: 24px is always 24 pixels.
rem works from the default text size, usually 16 px. So 2.5rem is 2.5 × 16 = 40 px. If someone sets their phone to bigger text, everything in rem grows with it.
% works from the parent. width: 50% makes a block half as wide as the block it sits in, on any screen.
Under the page is the box model of the booking block: make the screen narrower with Width, and the width follows.
#name { font-size: 2.5rem;}#booking { width: 50%; background-color: #fde2e4;}Try it yourself
Give the price list (.price-list) a light pink background (#fde2e4) and make it 80% as wide as the page, on every screen.
/* 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