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

Kevin Lewis
seal-mask
.a{fill-rule:evenodd;}techdegree
Kevin Lewis
Front End Web Development Techdegree Student 9,667 Points

Media Queries

How would I go about setting up my media queries for a mobile view of 768px and a desktop of 1024? So far I have @media (min-width: 768px) .container {width: 768px; margin: 0 auto;} Not sure what else I would need to add to this statement to make it a true mobile first approach and then use that information to create the desktop view. Appreciate the help.

Martin Coutts
Martin Coutts
18,154 Points

It's difficult to say without seeing what your site looks like. To change it for the desktop place the code in a media query for min-width 1024px. You could also use bootstrap or flexbox to make dynamic grids which will change depending on the viewport size. Also use the mobile media query to hide things that are unnecessary in the mobile view but bring them back in the desktop.

1 Answer

If you're using the mobile first approach, you only need media queries when writing for tablet or desktop. For example, I'll change the size of a container:

Mobile:

.container {
  width: 100%;
}

Tablet:

@media(min-width: 768px) {
  .container {
    width: 50%;
  }
}

Desktop:

@media(min-width: 1024px) {
  .container {
    width: 33.3333%;
  }
}

Hope this help!