Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

min-width media query not working on ipad?

Why isnt the following media query being picked up on iPads in landscape mode?

@media all and (min-device-width: 1000px) {
    css here
}

Or

@media all and (min-width: 1000px) {
    css here
}

I want this css to target any browser which is 1000px wide or over, not just ipads. For this reason id rather work with the 2nd option of min-width not min-device-width if possible. Both versions work fine with firefox on my PC. Thanks

like image 434
Evanss Avatar asked Oct 11 '11 12:10

Evanss


People also ask

How do you fix media query not working?

This may be the reason why your media queries aren't working. That is to say, you may have declared CSS within your HTML document. So if this is the case, simply go through the HTML document and remove the CSS declared inline. Alternatively, you can override the inline CSS with !

How do you give min and max width in media query?

Max-width and min-width can be used together to target a specific range of screen sizes. @media only screen and (max-width: 600px) and (min-width: 400px) {...} The query above will trigger only for screens that are 600-400px wide. This can be used to target specific devices with known widths.

How do you change the width of a media query?

Setting a particular "width-range" isn't any different from the way media queries are created. The only difference is the addition of more media feature expressions (that is, the screen width sizes). Take a look: @media only screen and (min-width: 360px) and (max-width: 768px) { // do something in this width range. }

What is the media query size for mobile?

320px — 480px: Mobile devices. 481px — 768px: iPads, Tablets. 769px — 1024px: Small screens, laptops. 1025px — 1200px: Desktops, large screens.


1 Answers

The iPad is always reporting its width as 768px and its height as 1024px, so you have to find out how it is rotated with orientation and use min-device-height:1000px like so:

     /* This will apply to all screens with a width 999px and smaller */
* {
     color:green;
     background-color:black;
}

     /*
       This will apply to all screens larger then 1000px wide 
       including landscape ipad but not portrait ipad. 
      */
@media (orientation:landscape) and (min-device-height:1000px),
       all and (min-width:1000px) {
    * {
        color:white;
        background-color:red;
    }
}

Results:

  • iPad
    • Portrait       - green text - black background
    • Landscape - white text  - red background
  • iPhone
    • Portrait       - green text - black background
    • Landscape - green text - black background
  • Computer (resolution)
    • 1680x1050 - white text  - red background
    • 800x600     - green text - black background

Using chrome & firefox (does anyone even use IE anymore?)

References:
w3 media queries
Safari CSS Reference
Optimizing Web Content

like image 132
chown Avatar answered Oct 14 '22 23:10

chown