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

Can someone solve this 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."

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

@media (min-width: 607px) {
  img:nth-child(3) {
    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>

4 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, arshia mohammadi! There are a few things going on here. First, instead of adding a new rule, you've changed the first rule you wrote. Secondly, you've accidentally deleted a closing curly brace. Your rule right now contains two open curly braces, but just one closing curly brace. You were meant to write a new rule with a new selector that clears the float you did on the previous step. Finally, in your nth-child you are picking the 3rd child and no other. But the challenge asks you to pick every third child starting with the fourth.

For example, if I wanted to pick every fifth child starting with the second I might write that like :nth-child(5n + 2). The 5n is every fifth child and the 2 is the starting point.

Hope this helps! :sparkles:

Steven Parker
Steven Parker
231,236 Points

The code from task 1 should be left as-is. For task 2 you will create a new rule.

Then, when setting up an "nth-child", the argument is based on both the repeating number an the starting number. The repeating part is followed by the letter "n", so for "every third" you would write "3n". Then the starting number is specified after a plus-sign, so for "the fourth ... element first" you would add "+4". So the entire argument would be "3n+4". Finally, add the property setting to your new rule and you should have it.

Happy coding! :crocodile:

Rob Allessi
Rob Allessi
8,600 Points

Please refrain from outright sharing of answers to Code Challenges on the forum. You can assist those seeking help by identifying what may be wrong with their code, etc.

Thanks you all so much