我想说我已经阅读并尝试了这里的说明的许多变体:
- http://www.cloudfour.com/ipad-css/
- 纯粹通过 css 检测 iPhone/iPad
- 检测 Xoom 浏览器 (Android)
- http://www.w3.org/TR/css3-mediaqueries/
- http://www.w3schools.com/html5/att_link_media.asp
- http://en.wikipedia.org/wiki/List_of_Android_devices
- http://en.wikipedia.org/wiki/File:Vector_Video_Standards2.svg
我想让我的页面根据所使用的设备使用不同的 CSS 文件。我已经看到了很多解决方案,都使用上述的某种形式。
但是,在 HTC Desire 上进行测试时,我始终会得到用于 iPad 的输出或完全未经过滤的输出。目前,我的测试代码基于:
http://www.cloudfour.com/ipad-css/
这是我的 HTML 文件:
<html>
<head>
<title>orientation and device detection in css3</title>
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:landscape)" href="iphone-landscape.css" />
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:portrait)" href="iphone-portrait.css" />
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape)" href="ipad-landscape.css" />
<link rel="stylesheet" media="all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait)" href="ipad-portrait.css" />
<link rel="stylesheet" media="all and (device-width: 480px) and (device-height: 800px) and (orientation:landscape)" href="htcdesire-landscape.css" />
<link rel="stylesheet" media="all and (device-width: 480px) and (device-height: 800px) and (orientation:portrait)" href="htcdesire-portrait.css" />
<link rel="stylesheet" media="all and (min-device-width: 1025px)" href="desktop.css" />
</head>
<body>
<div id="iphonelandscape">iphone landscape</div>
<div id="iphoneportrait">iphone portrait</div>
<div id="ipadlandscape">ipad landscape</div>
<div id="ipadportrait">ipad portrait</div>
<div id="htcdesirelandscape">htc desire landscape</div>
<div id="htcdesireportrait">htc desire portrait</div>
<div id="desktop">desktop</div>
</body>
</html>
这是 iPad 的 Landscape CSS 文件(我只在这里提供,因为它们基本相同:
div
{
display: none;
}
#ipadlandscape
{
display: inline;
}
我想知道要对链接元素进行哪些修改,以确保 ipad 仅获得其样式表,iphone 获得自己的样式表,并且(在这种情况下)htc 愿望(或相同分辨率/方面的设备)获得该样式表。