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 How to Make a Website Responsive Web Design and Testing Build a Three Column Layout

Amanda Rivera
Amanda Rivera
788 Points

My portfolio gallery images are not shrinking into two columns when the browser is smaller.

Here is my responsive.css code below. Please let me know what is missing. I also don't know how to attach my code with this question.

@media screen and (min-width: 480px) {

/********************************** TWO COLUMN LAYOUT ***********************************/

#primary { width:50%; float: left; }

#secondary { width: 40%; float: right; } }

/********************************** PAGE: PORTFOLIO ***********************************/

gallery li {

width:28.3333% }

gallery li:nth-child(4n) {

clear: left; }

@media screen and (min-width: 660px) {

}

3 Answers

Abe Layee
Abe Layee
8,378 Points

From the look of your code, I don't see you selecting the right element which is the # to target the gallery. It should be like this #gallery li... this means target all the li inside the #gallery. In addtion, the second issue is not using the :nth-child() pseudo class correctly. Thirdly, you have additional clsoing bracket on the #primary element. Check the MSD for more information using the :nth-child() selector @ https://developer.mozilla.org/en-US/docs/Web/CSS/%3Anth-child

/********************************** TWO COLUMN LAYOUT ***********************************/

#primary { width:50%; float: left; }

#secondary { width: 40%; float: right; } 

/********************************** PAGE: PORTFOLIO ***********************************/

#gallery li {

width:28.3333% }

#gallery li:nth-child(3n + 1) {

clear: left; }

@media screen and (min-width: 660px) {

}
Amanda Rivera
Amanda Rivera
788 Points

THANK YOU! Abraham and Chris. Both of your suggestions help me fix this issue.

First thing I notice is there's a second curly brace after the #secondary so you've closed your first media query before gallery li and gallery li:nth-child are rendered. If that's not on purpose I would start there. Hope it helps.

click the Markdown Cheatsheet link for info on posting code.

@media screen and (min-width: 480px) {

/********************************** TWO COLUMN LAYOUT ***********************************/

#primary { width:50%; float: left; }

#secondary { width: 40%; float: right; } }

/********************************** PAGE: PORTFOLIO ***********************************/
gallery li {

width:28.3333% }
gallery li:nth-child(4n) {

clear: left; }

@media screen and (min-width: 660px) {

}
Amanda Rivera
Amanda Rivera
788 Points

Thanks for the suggestion. It helped.

I am having the same issue and have referred to this for an answer but don't clearly see one.