Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS CSS Foundations Advanced Selectors Pseudo-Classes: :nth-child

Carl Hart
Carl Hart
4,870 Points

Advanced selectors - nth-child

I am doing the code challenge for selecting all the even list items from the ul , so my code is:

'''css

ul:nth-child(even) { color: white; background-color: black; } '''

However, this is somehow wrong, it keeps asking me to check my selector and make sure I have changed the background color to black, where am I going wrong??

2 Answers

Hi Carl Hart , see if this hint helps you: "Use the :nth-child pseudo-class to target the even list items only." Basically you are missing something in your selector.

Let me know if you still have issues figuring out how to solve this exercise.

Carl Hart
Carl Hart
4,870 Points

ah, okay thank you, so it should be '''css li:nth-child(even) { color: white; background-color: black; } '''

The error of my thinking was because the list items are nested (and therefore direct children) of the ul, so somehow it seemed to make more sense to say ul:nth-child(even), oops! thank you for your help!

Jonathan Gurr
PLUS
Jonathan Gurr
Courses Plus Student 1,859 Points

lol I made the same mistake, thanks to both for your help.