Android浏览器中的媒体查询失败

4

我正在开发一个网页应用程序,根据设备(及其方向)应用适当的样式表。

总共有5个媒体查询:

//for mobile phones in portrait mode
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:portrait)" href="css/mobile-portrait.css">

//for mobile phones in landscape mode
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:landscape)" href="css/mobile-landscape.css">

//for tablets (iPad) in portrait mode
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="css/tablet-portrait.css">

//for tablets (iPad) in landscape mode
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="css/tablet-landscape.css">

//for desktop computers
<link rel="stylesheet" media="all and (min-device-width: 1025px)" href="css/desktop.css">  

在桌面、iPad和iPhone上(无论是浏览器还是Web应用程序版本),一切都正常工作,但横向媒体查询在Android浏览器上失败了? 有什么想法吗?我是否错误地使用了“max-device-width”?


Web 设备通常不会报告您所期望的内容,因此它们对媒体查询的反应可能与您想象的不同。也许将测试浏览器指向 http://www.ckollars.org/dimensions-no-meta-viewport.html 和 http://www.ckollars.org/dimensions-meta-viewport.html 并查看它们的反应会很有用。 - Chuck Kollars
2个回答

1
这是因为大多数新的安卓手机都是480像素宽,800像素高,具体取决于设备。所以你写的方式,安卓横屏应该被平板电脑横屏CSS所识别。但我认为我遇到了类似的安卓无法识别样式表的问题,所以我添加了这个代码,一切似乎都正常了...
<meta name="viewport" content="width=device-width"> 

你的头部代码中是否包含了样式表链接?

0

在Droid1上,视口大小为320 x 569。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接