css · level 3 · unit 2 · lesson 2
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
matches like :is(), but weighs nothing.
:where() works like :is(): it matches any selector in its brackets. The difference is weight. Whatever you put inside, :where() adds zero specificity, so the rule counts as if that part were not there.
That makes it perfect for a , the small set of rules at the top of a stylesheet that clears the browser's own styles. A reset should set starting points that a later rule with one class can change.
Libraries shared by many teams wrap their selectors in :where() for the same reason: your own rules win without a fight.
<ul class="menu">
<li>Home</li>
<li>Shop</li>
</ul> :where(ul, ol) {
margin: 0;
padding: 0;
}
.menu {
padding: 12px;
background-color: #f4a261;
} Press show my page to see it here.
guess first
An id inside :where(). Which colour wins?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<header id="site">
<a class="logo" href="https://example.com/">Fern</a>
</header> :where(#site) a {
color: navy;
}
a {
color: crimson;
}
your turn
Your turn. Make a reset any class can beat.
Wrap the reset's selector in :where() so the .note rule wins on its paragraph without changing either selector. The plain paragraph keeps the reset's colour.
the page you’re styling
<article id="main">
<p>Lunch is at noon.</p>
<p class="note">Bring your own lunch.</p>
</article>your css
Press show my page to see it here.
- the note wins with one classnot checked yet
- the note keeps its marginnot checked yet
- the reset still styles plain paragraphsnot checked yet
fix it
The Save button ignores its colours. Can you fix it?
the page you’re styling
<div class="toolbar">
<button class="btn-primary">Save</button>
</div>your css
Press show my page to see it here.
- the button is tealnot checked yet
- the button text is whitenot checked yet
.btn-primaryloses to the first rule. Weigh each selector.:is(.toolbar) buttonweighs a class and a tag, one tag more than.btn-primary.- Swap
:isfor:where, so the first rule weighs only its tag, then press run.
nailed it
you wrote rules that never pick a fight. :D
:where()matches like:is()but weighs nothing.- Use it for resets and shared defaults.
- Then a single class can change them.
new words in your collection
- :where()
- reset
This lesson isn’t saved. A free account remembers every lesson you finish.