css · level 1 · unit 4 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A # picks the one element with that id.
An id is a name only one element on the page wears. An is a # followed by the name: #winner picks the element with id="winner".
Use a class for things that repeat, like every price or every tip. Use an id for one-off things, like the main title or the logo.
The # is the same sign that starts a hex code. At the start of a selector it means id. As a value, it starts a colour, like #ffd700.
<h1 id="title">Dog show results</h1>
<ul>
<li id="winner">Rex</li>
<li>Biscuit</li>
<li>Pepper</li>
</ul> #winner {
background-color: #ffd700;
font-weight: bold;
} Press show my page to see it here.
The id in the HTML has no #. The # only goes in the CSS.
guess first
A class and an id with the same name. Which line changes?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<p class="pet">Rex is a dog.</p>
<p id="pet">Pickles is a cat.</p> #pet {
color: orange;
}
your turn
Your turn. Crown the champion.
Fill in the id selector so only the champion gets the gold background. Use the #.
the page you’re styling
<h1>Spelling bee</h1>
<ul>
<li>Ava</li>
<li id="champion">Sam</li>
<li>Noor</li>
</ul>your css
Press show my page to see it here.
- the champion has a gold backgroundnot checked yet
- the others stay plainnot checked yet
fix it
The logo will not turn brown. Can you fix it?
the page you’re styling
<h1 id="logo">Pancake Palace</h1>
<p>Open every morning.</p>your css
Press show my page to see it here.
- the logo is chocolate brownnot checked yet
- The rule picks nothing. Does the HTML use a class or an id?
- The HTML says
id="logo", but a dot is for classes. - Change
.logoto#logo, then press run.
nailed it
you found one element by its id. :D
#namepicks the one element with that id.- Use classes for repeats and ids for one-offs.
- A dot for a class, a
#for an id.
new words in your collection
- id selector
This lesson isn’t saved. A free account remembers every lesson you finish.