CSS multimedia query issues with iOS devices

I have the following media queries configured to target various iOS devices (iPad3, iPad2, iPhone4, iPhone3). When I load this page from iPhone3 and iPad2, the correct divs are colored. When I download this page from iPad3, however, iPad2 and iPhone4 styles load, but NOT iPad3. (I can’t check iPhone4 at the moment.) Any ideas?

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<link rel="stylesheet" href="ipad3.css" media="only screen and (min-device-width:1536px) and (max-device-width:2048px) and (-webkit-min-device-pixel-ratio:2)" type="text/css" />
<link rel="stylesheet" href="ipad2.css" media="only screen and (min-device-width:768px) and (max-device-width:1024px) and (-webkit-min-device-pixel-ratio:0)" type="text/css" />
<link rel="stylesheet" href="iphone4.css" media="only screen and (min-device-width:640px) and (max-device-width:960px) and (-webkit-min-device-pixel-ratio:2)" type="text/css" />
<link rel="stylesheet" href="iphone3.css" media="only screen and (min-device-width:320px) and (max-device-width:480px) and (-webkit-min-device-pixel-ratio:0)" type="text/css" />
</head>

<body>
<div id="ipad3" style="width:200px;height:200px;border:1px solid black"></div>
<div id="ipad2" style="width:200px;height:200px;border:1px solid black"></div>
<div id="iphone4" style="width:200px;height:200px;border:1px solid black"></div>
<div id="iphone3" style="width:200px;height:200px;border:1px solid black"></div>

ipad3 should be RED
<br>
ipad2 should be GREEN
<br>
iphone4 should be BLUE
<br>
iphone3 should be ORANGE
</body>
</html>

.. and 4 css files are encoded respectively (this example is the iPad3.css file):

#ipad3 { background-color: red; }
+5
source share
3 answers

Since you have the width of the viewport set to the width of the device, the iPad3 screen resolution will still be displayed as 1024x768, but the pixel ratio of the device will be 2.

+4

iPad iPad 3, :

<link rel="stylesheet" href="ipad3.css" media="only screen and (min-device-width:768px) and (max-device-width:1024px) and (-webkit-min-device-pixel-ratio:1.5)" type="text/css" />

, iPad iPad 2.

0

Robbo, your code uses: -webkit-min-device-pixel-ratio:0which is invalid. Devices without a retina will have a pixel ration of 1. Probably why the iPad 3 matches both stylesheets.

0
source

All Articles