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

3,690 Points

Is it a mistake in li:nth-child code challenge?

I have been confused with this task.

TASK: Create a new rule that targets the first 4 list items only. Set the font weight to bold.

First, without thinking I write:

li:nth-child(4n+1) {
  font-weight: bold;

And the system says it's OK. But then I thought, that something is odd with this code. If we need to target only first 4 list items, then the code must be:

li:nth-child(-n+4) {
  font-weight: bold;

Because first code tells us to target every fourth list item starting with the first one. Am I right?

Both codes were accepted by the system, but I'm sure there is something wrong with it.

2 Answers

Hi Pavel,

Your reasoning is correct. The first one selects 1, 5, 9, 13, ...

The challenge seems to be broken. All that seems to matter is that the 1st item is selected regardless of what else is or isn't selected.

Your second answer should be the correct one. That selects the 4th item and every item that comes before it.

You may want to email support about this.

3,690 Points

Thank you for confirming my guess.

Thought I was losing my mind, relieved to see I am not the only one!

Contribution /* Write your CSS below */ Task 1 li:nth-child(-n+3) { color: white; background-color: black; } task 2 li:nth-last-child(2n+3) { color: white; background-color: #FF6347; }

task 3 li:nth-child(-n+4) { font-weight: bold; }