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

2 Column not working, stuck in 3 Column structure even when window is reduced to mobile size.

Here is my code from main.css...

gallery {

margin: 0; padding: 0; list-style: none; }

gallery li {

float: left; width: 45%; margin: 2.5%; background-color: #f5f5f5; color: #bdc3c7;

}

gallery li a p {

margin: 0; padding: 5%; font-size: 0.75em; color: #bdc3c7; }

Here is my code from responsive.css...

gallery li {

width: 28.3333%;

}

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

clear: left; }

Any help would be much appreciated. Thank You.

2 Answers

Hi Alfonso,

Erik is right. You need to use something like the following structure below your current CSS -

@media screen and (min-width: 400px) {
   body {
      background: green;
  }
}

and within the first set of brackets type the css code you want to be implemented once your screen hits a certain size. In the above example, when the screen width is greater than 400px the body's background will change color to green.

Hope that helps,

Ede

Alfonso Nevarez
Alfonso Nevarez
620 Points

Thank you both for your help. Concerning the media queries, I am unsure of what exactly it is that I am doing wrong. Here is what I have so far...

@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) {

}

I would be grateful for more input.

Erik McClintock
Erik McClintock
45,783 Points

Alfonso,

If you're wanting to rearrange your page structure when the browser is resized, you will need to use media queries.

Erik