简体   繁体   English

为什么“宽度=设备宽度”完全不起作用?

[英]Why is "width=device-width" totally not working?

I have a problem with setting media queries on devices.我在设备上设置媒体查询时遇到问题。 It doesn't work at all.它根本不起作用。 It works like normal width.它像正常宽度一样工作。 Why is that?这是为什么?

<meta charset="UTF-8" content="initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0, width=device-width">

And this is how I use it:这就是我使用它的方式:

@media only screen and (min-width: 600px) {
    background-color: lightblue;
}

It is very simple.这很简单。 You didn't put background-color: lightblue;你没有把background-color: lightblue; in a tag it should be in something like a html or body tag.在标签中,它应该位于htmlbody标签之类的东西中。

You should also update your meta tag to您还应该将元标记更新为

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

Your code should look something like this:您的代码应如下所示:

 html{ background-color:red; } @media only screen and (min-width: 600px) { html{ background-color: lightblue; } }
 <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">

If you want the webpage to turn light blue when it is smaller then 600px you should swap the two colors如果您希望网页在小于 600 像素时变成浅蓝色,则应交换两种颜色

For more info you can go to w3schools they explain media queries very clearly.有关更多信息,您可以访问w3schools,他们非常清楚地解释了媒体查询。

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

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