Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!