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 Selectors Advanced Selectors :nth Pseudo-Class Challenge

Confused on this challenge task. Question 2 of 3

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.

style.css
/* Write the CSS in the media query below */

@media (min-width: 607px) {
  img {
   float: left;
  }

}
index.html
<!DOCTYPE html>
<html>
<head>
    <title>Selectors</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="page.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
    <img src="thumb-forest.jpg" alt="">
    <img src="thumb-resort.jpg" alt="">
    <img src="thumb-trees.jpg" alt="">
    <img src="thumb-falls.jpg" alt="">
    <img src="thumb-view.jpg" alt="">
    <img src="thumb-sunset.jpg" alt="">
    <img src="thumb-lake.jpg" alt="">
    <img src="thumb-beach.jpg" alt="">
    <img src="thumb-bay.jpg" alt="">
    <img src="thumb-peaks.jpg" alt="">
    <img src="thumb-falls.jpg" alt="">
    <img src="thumb-resort.jpg" alt="">
</body>
</html>

9 Answers

Donald Wilson
Donald Wilson
5,418 Points

Here is the code I used to get the correct answer for the question on Challenge Task 2 of 3

"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."

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

4n + 3 isn't every 7th child. It means start with the 3rd child then select every 4th child after that.

"...targets the fourth img child element first, then every third img that follows"

This would be 3n+4.

Also, for this {clear: float-left;} , it should be {clear: left;}

Thanks Derek!!

@media (min-width: 607px) { img{ float: left;

} img:nth-child(3n+4){ clear: left; } }

Richard Targett
Richard Targett
4,960 Points

If only treehouse offered hints -_-

very helpful. But if your not 100% sure of this logic whats the best way to let this stuff sink in? [Practice] Im guessing?

Chris

There's two errors in your error.

  1. 4n already refers to the 4th child - I don't even know if 4n + 3 works but if it does it's referring to every 7th child
  2. clear is a property all in itself, like float, you don't have to re-state float, you just indicate the 'direction' where you want to clear (left, right, both are the standard options)

John,

Thanks for explaining it in detail, it really helped me out. Thanks again!

This is the correct answer:

img:nth-child(3n+4){ clear: left; }

The video before the quiz goes into this

You need to use nth-child(4n).

Thanks John for replying... I wrote this img:nth-child(4n + 3) {clear: float-left;} Got an error.