HTML und CSS · Junior · Frage 35 von 75
Wie färbt man das letzte Element einer Liste beliebiger Länge ohne JavaScript rot?
- 1
li:nth-child(10) { color: red; } - 2
li::last { color: red; } - 3
li:last-child { color: red; }
Antwort zeigen
Richtige Antwort: li:last-child { color: red; }
Erklärung
:last-child trifft ein Element, das das letzte Kind seines Elternelements ist. Es gibt auch :last-of-type (letztes Element seines Typs) und :nth-last-child(). nth-child(10) funktioniert nur bei genau 10 Einträgen, und ein Pseudoelement ::last gibt es nicht.