我一直在寻找这个答案,但我似乎找不到它。我只有iPhone和iPad - 我没有Android - 所以我不知道我的CSS是否甚至触及Droid?
这就是我的HTML和CSS中的内容:
HTML
<meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1.0">
CSS
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation: landscape) {
... CSS for iPad landscape
}
@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation: portrait) {
... CSS for iPad portrait
}
@media only screen and (max-device-width: 480px) {
... CSS for iPhone portrait and landscape
}
问题:
您可以在此处查看示例页面:http://www2.receivablesxchange.com/alternative-to-factoring-4
答案 0 :(得分:3)
媒体查询用于显示区域和类型。它不会查看用户代理或类似的东西。使用JQuery + CSS,你能做的就是这样:
var _device = {};
if (navigator.userAgent.match(/iPad/i)) {
_device.name = 'ipad';
_device.type = 'mobile';
} else if (navigator.userAgent.match(/android/i)) {
_device.name = 'android';
_device.type = 'mobile';
} else {
_device.type = 'desktop';
}
$('body').addClass(_device.name).addClass(_device.type);
现在,在CSS中,您只需添加适合您需求的正文类:
@media only screen and (max-device-width: 1024px) {
.ipad #myDiv {
// css for #myDiv only seen on the iPad
}
.android #myDiv {
// css for #myDiv only seen on the Android
}
.mobile #myDiv {
// css for #myDiv available to iPad AND android but NOT desktop
}
}