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

Code Challenge: pseudo-class :nth-child

I need to select the 3rd list item only and change the background color to a specific hex color. Here is my current code:

li:nth-child(even)      {
    color: white;
  background-color: black;
}
li:nth-child(3)
        {
  background-color: FF6347;
}

I'm guessing the problem is that I can't use :nth-child twice? Does this defeat its' purpose?

Thanks!

4 Answers

Chase Lee
Chase Lee
29,275 Points

You need to put "#" before the hex value.

Kevin Korte
Kevin Korte
28,149 Points

You can use the :nth-child as many times as you possibly want. The last pseudo class will just override the one before it if you target the same element twice.

Your problem is much more simple. You forgot the # [hashtag] before you defined your hex color value FF6347.

Do this: #FF6347

It'll work.

Ah, thank you both for the input. I couldn't find any information out there that I couldn't use the ":nth-child" multiple times but it was the only logical explanation I could think of haha. Thanks again for the quick responses!