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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Alexander Kenemer](https://uploads.teamtreehouse.com/production/profile-photos/1390442/micro_boat.jpg)
Alexander Kenemer
2,089 PointsCSS portfolio image positioning messes up between mobile and bigger.
I've finished the "How to Build a Website" class and have used my own images and description for the portfolio. Since the beginning, building the mobile version, my 5th image was bumped down by the description of the 3rd. I learned about the:
gallery li:nth-child(5n) {
clear: left;
}
I've tried it in various ways within my responsive and main css files, however I can't get it to work for both my mobile and expanded versions of the site. Currently, I created an @media screen set to 0 and within there I cleared it left, then my media screen set to 480px I floated it back left, but it doesn't work in both.
Help?
5 Answers
![dylan goddard](https://uploads.teamtreehouse.com/production/profile-photos/1438082/micro_Goddard_Dylan-LOW.png)
dylan goddard
12,752 PointsHave you tried
gallery li:nth-child(4n) {
clear:left;
}
I'm pretty sure you need to clear the first image in the second row. And remember to ad the hash (#) before you #gallery id selector.
![Zhihao Wang](https://uploads.teamtreehouse.com/production/profile-photos/1420382/micro_11665559_1106710559342430_7080323060889785464_n.jpg)
Zhihao Wang
9,687 PointsI think your problem is that you do not have the hash symbol to tell the stylesheet that you are targeting an id.
You also need to apply this style to the 4th image, instead of the 5th.
Here's the new version:
#gallery li:nth-child(4n){
clear: left;
}
![Alexander Kenemer](https://uploads.teamtreehouse.com/production/profile-photos/1390442/micro_boat.jpg)
Alexander Kenemer
2,089 PointsSorry guys, Though you're both correct that I forgot to add the # in my post, it was in my actual code and that wasn't the problem I was experiencing. Turns out, depending on the size, I needed to kick every other image (when small) and every 3rd image (when big.) My teacher told me not to use (5n), but to solve it with more complex math:
/*3, 5, 7, 9 */
gallery li:nth-child(2n+1){
clear left; }
/4, 7, 10, 13/
gallery li:nth-child(3n+1){
clear left; }
However, when I did that, it was still messing up. Figured out, my 'children' weren't overwriting each other, but combining. So it was kicking 3,4,5,7,9,10. What I had to do was set a max screen size for the small, so it would reset when I extend beyond that size. Here's my working responsive.css
@media screen and (min-width: 0px) and (max-width: 479px){ #gallery li:nth-child(2n+1) { clear: left; } }
@media screen and (min-width: 480px) {
#gallery li { float: left; width: 28.3333% }
#gallery li:nth-child(3n+1) { clear: left; }
}
![dylan goddard](https://uploads.teamtreehouse.com/production/profile-photos/1438082/micro_Goddard_Dylan-LOW.png)
dylan goddard
12,752 PointsCool! Thanks for sharing your solution with us, glad to see you got things working!
![Boris Schrenzel](https://secure.gravatar.com/avatar/e8a1ddc8341ef17a8db070709402e4d0?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Boris Schrenzel
2,395 Pointsawesome Alexander Kenemer, I spent 2 weeks trying to figure out what was wrong with my code (after changing the pic size). You solved it for me here thanks a lot !
![Alexander Kenemer](https://uploads.teamtreehouse.com/production/profile-photos/1390442/micro_boat.jpg)
Alexander Kenemer
2,089 PointsGlad it's helpful, I'm sorry the code didn't copy properly.