Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I apply a stylesheet just to the iPhone (and not IE), without browser sniffing?

I’d like to apply a stylesheet exclusively to the iPhone, without doing browser sniffing (via the user-agent string) on the server or via JavaScript.

I particularly don’t want Internet Explorer to apply the stylesheet. Apple’s suggested code for applying an iPhone-specific stylesheet, i.e.:

<link media="only screen and (max-device-width: 480px)" href="small-device.css" type= "text/css" rel="stylesheet">

seems to cause the stylesheet to be applied by IE 7 and 6.

like image 469
Paul D. Waite Avatar asked Dec 08 '22 07:12

Paul D. Waite


1 Answers

Use Apple’s suggested code, but wrap it in conditional comments to hide it from IE:

<!--[if !IE]><!-->
<link media="only screen and (max-device-width: 480px)" href="small-device.css" type= "text/css" rel="stylesheet">
<!--<![endif]-->

Credit I think to Sitepoint’s iPhone development article for this.

like image 63
Paul D. Waite Avatar answered Dec 09 '22 20:12

Paul D. Waite