HTML & CSS · Junior · Question 35 of 75
How do you make the last item of a list of any length red without JavaScript?
- ✓Correct answer:
li:last-child { color: red; } - 2
li:nth-child(10) { color: red; } - 3
li::last { color: red; }
Explanation
:last-child matches an element that is the last child of its parent. There are also :last-of-type (last element of its type) and :nth-last-child(). nth-child(10) only works with exactly 10 items, and there is no ::last pseudo-element.