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

Alfonso Nevarez
Alfonso Nevarez
620 Points

How do i get the Gallery to collapse to a two column structure when minimizing the window to mobile dimensions?

My gallery stays in a 3 column structure. Here is my code, please assist if you can, I would appreciate it. Thank You.

@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(3n+1) {

clear: left; }

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

}

1 Answer

First thing you should do is add your gallery to the first media query, and then add the display property block to your gallery. I would also add the display property inline-block to your primary and secondary columns. Also you need to add an identifier to your gallery element, either a class or ID. just plain 'gallery' won't get you anywhere in HTML since it is not a semantic tag. Try this:

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

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

primary {

display: inline-block; width: 50%; float: left; }

secondary {

 display: inline-block;
 width: 40%; 
 float: right; } 

.gallery { display: block; width: 90% } }

This should give you a two column layout with the gallery underneath or on top of your columns depending on your HTML markup. If 'gallery' is an ID, simply add # in place of the period.

Hope that helps!

I also suggest checking out documentation on media queries here: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries. Media queries can be tricky but super useful once mastered.

Alfonso Nevarez
Alfonso Nevarez
620 Points

Thank you so much for your help :)