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

Stephen Sim
Stephen Sim
2,956 Points

nth-child challenge. its not working?

I'm working on a structural pseudo-class code challenge. The problem is as follows:

"Use the :nth-child selector to select the even list items only. Set the color to white and the background color to black."

the code i wrote was:

li:nth-child (even) {
  color: #FFF;
  background-color: #000;
}

Am I missing something?

2 Answers

Lee Hughes
Lee Hughes
8,380 Points

Lose the space between child and (even)

;)

Stephen Sim
Stephen Sim
2,956 Points

amazing how a simple space can mess everything up.. gah! thanks!

James Barnett
James Barnett
39,199 Points

Stephen Sim - Moral of the story: A spaces inside of a CSS selector is interpreted as the combinator for a descendant selector.

Giles Rafol
Giles Rafol
1,060 Points

I didn't try it on this one, but one time I had to actually use the color keywords to pass. So try white and black instead of the hex values.

James Barnett
James Barnett
39,199 Points

Color keywords translate to specific hex colors, if they ask for lighblue you'd need to look up what the exact hex code is equal to lightblue as not just any color that light-ish blue will do.

Here's the offical color keyword list and their associated hex code.