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 How to Make a Website Responsive Web Design and Testing Refactor the Layout

Jason Larkin
Jason Larkin
13,970 Points

Clearing every 4th item in the gallery list items not working.

#gallery li: nth-child (4n){ clear: left;}

The above CSS SHOULD be the solution to Refactor the Layout code challenge #2 but it won't accept it. Any ideas? Thanks.

4 Answers

Lauren Clark
Lauren Clark
33,155 Points

Oh right.

#gallery li:nth-child(4n) { clear: left;}

You have a space prior to the 4n expression, and after the colon. Try that, without the spaces.

I been banging my head over this. I was missing 'n', what's n stand for?

Lauren Clark
Lauren Clark
33,155 Points

It's a counter. So we're saying here, for every nth child, on the nth step, do this.

So 4n would select every third item, missing out the first and second. If you just had 4 in there, without the 'n' it would just select the 4th child that one time.

n is looping over the children of li, counting every 4th step, and applying the code in the block, which in this case is clearing the left float.

n is 0 indexed so we're actually clearing the third item, so that it doesn't affect the 4th.

Lauren Clark
Lauren Clark
33,155 Points

If you post your code and the question, I can take a look?

Jason Larkin
Jason Larkin
13,970 Points
#gallery li: nth-child (4n){ clear: left;}

This should be the proper code but it isn't working. Thank you in advance for your response.

Jason Larkin
Jason Larkin
13,970 Points

Thank you Lauren, that worked!