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

Robert Kooyman
Robert Kooyman
4,927 Points

Nth-child selectors

The challange mentiones that I am doing it wrong, but I cannot see why:

CHALLENGE: We want three floated images per row. In the media query, create a pseudo-class selector that targets the fourth img child element first, then every third img that follows. Then, add a clear property that clears the left float.

CODE: /* Write the CSS in the media query below */

@media (min-width: 607px) { img { float: left; } img:nth-child(4n+3) { float: clear; }

ANSWER: Bummer! Are you using :nth-child expression that selects the 4th img child first, then every 3rd img?

1 Answer

Kailash Seshadri
Kailash Seshadri
3,087 Points

Hello Robert!

Notice that in your code u have used :nth-child(4n+3) this means you are selecting every 4th img, starting from the 3rd... change your code to be as follows:

@media (min-width: 607px) {
  img {
    float: left;
  }
  img:nth-child(3n+4) {
    float: clear;
  }
}

Change the code from ':nth-child(4n+3)' to ':nth-child(3n+4)'. By 3n+4, you are selecting every 3rd img starting form the 4th.

Happy Coding!