简体   繁体   English

媒体查询不起作用

[英]Media queries doesn't work

Does anyone know why my media queries code doesn't work ? 有谁知道为什么我的媒体查询代码不起作用?

 <div class="box"></div> 
 .box {
     background-color: red;
     width: 100%;
     height: 50px;
 } 

 @media only screen and (max-device-width: 768px)  {
     .box {border: 5px solid blue;}
 }

http://jsfiddle.net/N9mYU/ http://jsfiddle.net/N9mYU/

You would use (max-width: 768px) instead of (max-device-width: 768px) . 您将使用(max-width: 768px)而不是(max-device-width: 768px) See the difference between max-device-width / max-width explained here . 请参阅此处说明的max-device-width / max-width之间的差异。

Add a viewport if you want the media query to work on mobile devices: 如果您希望媒体查询在移动设备上运行,请添加视口:

<meta name="viewport" content="width=device-width, initial-scale=1">

UPDATED EXAMPLE HERE 这里有更新的例子

@media only screen and (max-width: 768px) {
    .box {
        border: 5px solid blue;
    }
}

Further reading: A pixel is not a pixel/Viewport width and screen width (mdn) 进一步阅读: 像素不是像素/视口宽度和屏幕宽度(mdn)

Sorry folks but this question just became moot: Firefox Dev edition just did an upgrade and changed how the device screens are presented: you can no longer select screen size by pixel using a drop down box; 对不起,但这个问题变得没有实际意义了:Firefox Dev版刚刚升级并改变了设备屏幕的呈现方式:你不能再使用下拉框选择屏幕尺寸; you now have to select the device name which will have its dimensions displayed. 您现在必须选择将显示其尺寸的设备名称。

I've long had problems when Firefox has issued an update while I have the browser open. 当Firefox打开浏览器时,我已经遇到了问题。

The regular Firefox browser with firebug is now more responsive. 带有firebug的常规Firefox浏览器现在响应更快。 Some of issues I have been dealing with is that when I set a limit such as "min-width 320px" FDE only performs the change at a larger min, say 380px. 我一直在处理的一些问题是,当我设置一个限制,例如“min-width 320px”时,FDE只会以更大的最小值执行更改,例如380px。 This does not change in the updated edition. 这在更新版本中没有变化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM