Challenge - 5 Problems
Nth-child Selector Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ selector
intermediate2:00remaining
What elements are selected by
li:nth-child(3n)?Given a list of
<li> items, which items will be styled by the CSS selector li:nth-child(3n)?CSS
<ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <li>Item 4</li> <li>Item 5</li> <li>Item 6</li> </ul>
Attempts:
2 left
💡 Hint
Remember that
3n means every 3rd element starting from 3.✗ Incorrect
The selector li:nth-child(3n) matches every 3rd <li> element: 3, 6, 9, and so on. In the example, only items 3 and 6 match.
🧠 Conceptual
intermediate2:00remaining
What does
:nth-child(odd) select?Which elements are targeted by the CSS selector
:nth-child(odd)?CSS
<div> <p>Paragraph 1</p> <p>Paragraph 2</p> <p>Paragraph 3</p> <p>Paragraph 4</p> </div>
Attempts:
2 left
💡 Hint
Odd means 1, 3, 5, and so on.
✗ Incorrect
The :nth-child(odd) selector matches elements in odd positions: 1st, 3rd, 5th, etc.
📝 Syntax
advanced2:00remaining
What error occurs with
li:nth-child(2n+)?Consider the CSS selector
li:nth-child(2n+). What happens when you use this selector in your CSS?CSS
li:nth-child(2n+) { color: red; }
Attempts:
2 left
💡 Hint
Check if the expression after '+' is complete.
✗ Incorrect
The expression 2n+ is incomplete because it lacks a number after the plus sign. This causes a syntax error and the selector is invalid.
❓ rendering
advanced2:00remaining
Which CSS rule colors only the 4th item in a list?
You want to color only the 4th
<li> item red. Which CSS selector and rule achieves this?CSS
<ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul>
Attempts:
2 left
💡 Hint
Use a selector that targets exactly the 4th child.
✗ Incorrect
li:nth-child(4) selects only the 4th <li> element, coloring it red.
❓ accessibility
expert3:00remaining
How does
:nth-child affect keyboard navigation and accessibility?If you use
:nth-child selectors to hide or style elements, what should you consider to keep your page accessible?Attempts:
2 left
💡 Hint
Think about how hidden or styled elements affect users who navigate with keyboard or screen readers.
✗ Incorrect
When using :nth-child to hide or style elements, ensure that hidden elements are also removed from keyboard focus and screen readers (e.g., using display:none or aria-hidden="true") to maintain accessibility.