【发布时间】:2016-11-28 05:41:52
【问题描述】:
我正在处理媒体查询,以开始让我的网站更具响应性。但是,媒体查询在我的 PC (Chrome) 上运行良好,但在移动设备(iPad 和 iPhone)上查看时,媒体查询似乎没有生效。我在头部有视口标签,但我猜我错过了其他东西......
CSS
@media (min-width:320px) {
/* smartphones, iPhone, portrait 480x320 phones */
#mainText {
color: pink;
}
}
@media (min-width:481px) {
/* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */
#mainText {
color: blue;
}
}
@media (min-width:641px) {
/* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */
#mainText {
color: red;
}
}
@media (min-width:961px) {
/* tablet, landscape iPad, lo-res laptops ands desktops */
#mainText {
color: yellow;
}
}
@media (min-width:1025px) {
/* big landscape tablets, laptops, and desktops */
#mainText {
color: green;
}
}
@media (min-width:1281px) {
/* hi-res laptops and desktops */
#mainText {
color: purple;
}
}
HTML
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<div id="mainText">
<h1>Text</h1>
<h2>Text</h2>
</div>
【问题讨论】:
-
尝试远程调试网页。一切看起来都很好,它应该可以工作。此外,手机使用非常重的缓存,因此请尝试使用隐私浏览选项卡以确保应用您的新样式。
-
1281px 的屏幕仍然会触发@media (min-width:320px)。您应该尝试使用范围。
-
我同意范围。现在,我只是想让它工作。我尝试在我的 iPad 和 iPhone 上的 Chrome 中打开一个“隐身标签”,但查询仍然没有生效......当我在设备上看到该页面时,#mainText 的文本是黑色的......
-
您的 CSS 中是否有一些重要的东西可能会覆盖您的规则?
-
看起来您在文本中添加了过滤器亮度。因为您没有使用 webkit 前缀 chrome 只是忽略它。试试把滤镜亮度去掉 1% 看看有没有帮助
标签: css media-queries