4

I am developing a responsive design website. The website will be optimized for iPhone and iPod (Both having width 640px).

I am using the following CSS3 media queries:

    @media screen and (max-width: 640px) {
        .display-none-mobile{
            display: none;
        }
    }
    @media screen and (min-width: 641px) {
        .display-none-desktop{
            display: none;
        }
    }

Above code works great on my desktop browsers when i shrink browser width to 640px. However the code does not work when i try to test the website on iPod using Safari browser.

I changed the CSS3 media queries to

    @media screen and (max-device-width: 640px) {
        .display-none-mobile{
            display: none;
        }
    }
    @media screen and (min-device-width: 641px) {
        .display-none-desktop{
            display: none;
        }
    }

Now, the responsive design worked for Safari on iPod but it messed up with layouts on all other desktop browsers. Those css3 media queries were totally ignored by oChrome, IE, FF on my desktop (for width 640px).

So by now i have figured out there is something related to cross browser compatibility with css3 media queries, but could not find much info about this. what can be the ways i can update my code to make css3 media queries working for all browsers (or atleast major ones). I am targeting atleast

  1. IE Windows
  2. Safari Windows
  3. Chrome Windows
  4. Firefox Windows
  5. Safari iPod
  6. Chrome iPod
CodeMonkey
  • 2,265
  • 9
  • 48
  • 94
  • 1
    Take a look at http://www.quirksmode.org/blog/archives/2010/09/combining_meta.html for some info regarding meta tags and media queries. I think might be what you're running into. The device width and content width are not the same, so the media query is actually working as expected, just not according to what you need. – aaronburrows May 08 '13 at 19:06

1 Answers1

12

If you don't add the following <meta> tag on your HTML the device will ignore your media queries

<!DOCTYPE html>
<html lang="en-us">
    <head>
        <meta name="viewport" content="width=device-width">
    </head>
    <body>
    </body>
</html>
Tom Leese
  • 19,309
  • 12
  • 45
  • 70
Vinícius Moraes
  • 3,506
  • 2
  • 22
  • 24