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 trialChris Paraoan
4,481 PointsConfused 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.
/* Write the CSS in the media query below */
@media (min-width: 607px) {
img {
float: left;
}
}
<!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
5,418 PointsHere 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
8,841 Points4n + 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;}
Chris Paraoan
4,481 PointsThanks Derek!!
ellie adam
26,377 Points@media (min-width: 607px) { img{ float: left;
} img:nth-child(3n+4){ clear: left; } }
Richard Targett
4,960 PointsIf 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?
John Magee
Courses Plus Student 9,058 PointsChris
There's two errors in your error.
- 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
- 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)
Chris Paraoan
4,481 PointsJohn,
Thanks for explaining it in detail, it really helped me out. Thanks again!
Andreas Snow
6,920 Pointsthanks
Kim Pham
Courses Plus Student 2,208 Pointsimg:nth-child(3n+4) { clear: left;} }
Jose A Reynaldo Vazquez
21,313 PointsThis is the correct answer:
img:nth-child(3n+4){ clear: left; }
John Magee
Courses Plus Student 9,058 PointsThe video before the quiz goes into this
You need to use nth-child(4n).
Chris Paraoan
4,481 PointsThanks John for replying... I wrote this img:nth-child(4n + 3) {clear: float-left;} Got an error.
Marcin Robert Kaźmierczak
33,570 PointsMarcin Robert Kaźmierczak
33,570 Points