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

岁酱吖の 提交于 2019-12-17 12:08:29

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/809532/how-do-i-apply-a-stylesheet-just-to-the-iphone-and-not-ie-without-browser-sni

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!