css · level 3 · unit 1 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
Custom properties inherit, so a section can bring its own values.
Custom properties inherit, the way color does. An element gets every token its parent has, and passes them on to its children. That is why tokens on :root reach the whole page.
Set the same token again on one element and you change it for that element and everything inside it, nothing else. That area is the token's .
So you write a once, reading var(--accent), and a wrapper like .promo sets a different --accent. Same rules, new look, no extra selectors.
<a class="btn" href="https://example.com/a">Read more</a>
<div class="promo">
<a class="btn" href="https://example.com/b">Get 20% off</a>
</div> :root {
--accent: teal;
}
.promo {
--accent: crimson;
}
.btn {
padding: 8px 16px;
color: white;
background-color: var(--accent);
} Press show my page to see it here.
The .btn rule never changes. Only the value it reads does.
guess first
Two wrappers set the same token. What does each badge get?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<div class="panel">
<span class="badge">New</span>
<div class="alert">
<span class="badge">Late</span>
</div>
</div> .panel {
--tone: navy;
}
.alert {
--tone: crimson;
}
.badge {
padding: 2px 8px;
color: white;
background-color: var(--tone);
}
your turn
Your turn. Give the warning its own colour.
Fill in the selector and a colour so only the note inside .warning changes. The first note must keep the default steel blue.
the page you’re styling
<p class="note">Doors open at six.</p>
<div class="warning">
<p class="note">The car park is full.</p>
</div>your css
Press show my page to see it here.
- the warning note has a new colournot checked yet
- the first note keeps steel bluenot checked yet
fix it
The sale card stayed teal. Can you fix it?
the page you’re styling
<div class="card">Free delivery</div>
<div class="sale">
<div class="card">Half price</div>
</div>your css
Press show my page to see it here.
- the sale card has a crimson bordernot checked yet
- the first card stays tealnot checked yet
- The
.salerule runs, but the card never hears about it. Compare the token names letter by letter. --acentand--accentare two different tokens to the browser.- Spell it
--accentinside.sale, then press run.
nailed it
you scoped a token to one section. :D
- Custom properties inherit from parent to child.
- Set a token again on a section to change it only there.
- A misspelt token name quietly makes a brand new token.
new words in your collection
- scope
- component
This lesson isn’t saved. A free account remembers every lesson you finish.