Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS3 media queries not working on Safari on iPod/iPhone

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
like image 797
CodeMonkey Avatar asked Dec 15 '22 11:12

CodeMonkey


1 Answers

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>
like image 54
Vinícius Moraes Avatar answered Feb 15 '23 12:02

Vinícius Moraes