Wednesday, 3 November 2010

Issue with using CSS check for iPad device width

Many people out there adopt the following way of using a stylesheet based on the max device width in order to use different styling for an iPad:

<link href="css/iPad.css" media="all and (max-device-width:1024px)" rel="stylesheet" type="text/css">

However after doing several browser checks in different resolutions for a site I had done just this on I found that if you were using a screen resolution of 1024x768 and the browser Google Chrome it uses the iPad css.

Therefore I had to change this strategy and instead now use the following code to get a better check on the device accessing the site:

<script type="text/javascript"> // <![CDATA[
if ((navigator.userAgent.indexOf('iPad') != -1)) {
document.write('<link href="css/iPad.css" media="all" rel="stylesheet" type="text/css">');
} // ]]></script>

Works perfectly now!!

No comments:

Post a Comment