css · level 3 · unit 3 · lesson 4
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
inside :has() lets the page react to a tick.
:checked matches a tick box or a , the round kind where picking one unticks the rest, while it is ticked. On its own it can only style that small box.
Inside :has() it reaches much further. .option:has(:checked) highlights the whole row around the ticked box, and form:has(#gift:checked) can reveal a gift message field. No script needed.
Here a box starts ticked when its tag includes the word checked. Click the options in the preview to watch the styles follow.
<label class="option"><input type="radio" name="plan" checked> Monthly</label>
<label class="option"><input type="radio" name="plan"> Yearly</label> .option {
display: block;
padding: 12px;
border: 2px solid #e5e7eb;
}
.option:has(:checked) {
border-color: #0f766e;
background-color: #e0f2f1;
} Press show my page to see it here.
guess first
The box is ticked. Which element changes?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
<div class="row">
<input type="checkbox" id="news" checked>
<label for="news">Send me the newsletter</label>
</div> .row:has(:checked) label {
color: #15803d;
font-weight: bold;
}
your turn
Your turn. Reveal the gift message.
Fill in the test inside :has() so the gift note shows only while the gift box is ticked. The box starts ticked.
the page you’re styling
<form class="checkout">
<label><input type="checkbox" id="gift" checked> This is a gift</label>
<p class="gift-note">Add a message on the next page.</p>
</form>your css
Press show my page to see it here.
- the gift note showsnot checked yet
- the test looks for a ticked boxnot checked yet
fix it
The chosen size never lights up. Can you fix it?
the page you’re styling
<label class="plan"><input type="radio" name="size" checked> Small</label>
<label class="plan"><input type="radio" name="size"> Large</label>your css
Press show my page to see it here.
- the chosen size has an outlinenot checked yet
- the other size has nonenot checked yet
- A label can never be ticked. Only the input inside it can.
.plan:checkedasks whether the label itself is ticked. You want to know whether it holds a ticked input.- Use
.plan:has(:checked), then press run.
nailed it
you built a page that reacts to a tick. :D
:checkedmatches a ticked box or radio button.:has(:checked)lets a whole row or form react.- Show and hide parts of a form with no script.
new words in your collection
- :checked
- radio button
This lesson isn’t saved. A free account remembers every lesson you finish.