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

Problem with responsive design/media queries

Hi! I'm building a website and I'm implementing the responsive method of designing for mobile first, and then, with media queries, adapt it to larger viewports. So, my code looks like this:

```body {general design} header {mobile design} a {mobile design} etc.

```@media screen and (min-width: 768px) {
  header {larger viewport design}
  a {larger viewport design}
  etc. 
}

When I see the website on a laptop or desktop works perfectly, but in a tablet or smartphone, the design is the same as in the laptop! Is just like zoom out... but it doesn't recognize the code for small viewports.

Can anyone help me, please?

5 Answers

Hi Sofia,

Are you using any meta tags like this?

<meta name="viewport" content="width=device-width, initial-scale=1.0">

This prevents the browser from doing any initial zooming out on the site to get it to fit.

Yes! It solves the mobile issue, thanks!... but now, in the larger version it doesn't recognize the code that applied for both... just the one inside the media querie. Do I have to repeat that code?

No... sorry, that isn't whats happening... It recognized basic and general code like background, fonts, etc.... but some parts doesn't display the css correctly, specifically header and footer.

Ok, do you have your general and mobile styles at the beginning of your custom css and outside of any media queries?

Then your media queries are simply overriding or adding to the previous general and mobile styles?

Maybe give an example of one part that isn't working correctly.

It sounds like your issue might be within the viewport of the head.

Try adding this code in your head tag:

<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

Code wasn't viewable.

<code><meta name="viewport" content="width=device-width, initial-scale=1.0 maximum-scale=1.0, user-scalable=no"></code>

            <meta name="viewport" content="width=device-width,  initial-scale=1.0">
            ```

Had to reference the Markdown Cheatsheet for syntax to work.

Ok, now is working I had to refresh a couple of times. Thanks a lot!

You're welcome.

Ignore my questions, I hadn't seen this comment yet.

Glad you sorted it out.