Lesson 1 · Unit 02
Selectors
Pick exactly the elements a rule should style
What you practise
- Type, class and id, descendant and child combinators, pseudo-classes, which elements a selector matches
Try a question from this lesson
Pick one
A CSS rule should turn "Tea" and "Sugar" red and leave "Milk" alone. Which selector picks exactly those two?
<p class="note">Tea</p>
<p>Milk</p>
<div class="note">Sugar</div>Hint
What do Tea and Sugar share that Milk lacks?
Correct answer
.note
Why
A dot selects by class, whatever the element type, so .note matches the first paragraph and the div. p would take Milk too, div only Sugar, and #note looks for an id that nothing here has.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
Selector, then declarations
A rule is a selector followed by declarations: property: value; pairs in braces. The selector decides which elements receive them.
A bare name matches every element of that type. .note matches every element with class="note". #total matches the one element with id="total".
p { color: gray; }
.note { color: red; }
#total { font-weight: bold; }11 more exercises in the app
- 5× type the answer
- 1× match the pairs
- 1× true or false
- 1× fill the blanks
- 3× multiple choice
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.