如何在不使用浏览器嗅探的情况下将样式表仅应用于 iPhone(而不是 IE)? [英] How do I apply a stylesheet just to the iPhone (and not IE), without browser sniffing?

查看:23
本文介绍了如何在不使用浏览器嗅探的情况下将样式表仅应用于 iPhone(而不是 IE)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将样式表专门应用于 iPhone,而不是在服务器上或通过 JavaScript 进行浏览器嗅探(通过用户代理字符串).

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.

我特别不希望 Internet Explorer 应用样式表.Apple 建议的用于应用 iPhone 特定样式表的代码,即:

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">

似乎导致样式表被 IE 7 和 6 应用.

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

推荐答案

使用 Apple 建议的代码,但将其包装在条件注释中以对 IE 隐藏:

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]-->

我认为这要归功于 Sitepoint 的 iPhone 开发文章.

这篇关于如何在不使用浏览器嗅探的情况下将样式表仅应用于 iPhone(而不是 IE)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆