简体   繁体   English

媒体查询只能在Firefox上运行,而不能在Chrome上运行

[英]Media Query works on Firefox but not on Chrome

I want to add some style for the screen size between 1024px to 1280px, so I'm using following media query: 我想为屏幕大小介于1024像素至1280像素之间的样式添加一些样式,因此我在使用以下媒体查询:

@media only screen and (min-width: 1024px) and (max-width: 1279px) {

My screen size is 1280px. 我的屏幕尺寸是1280像素。 The Firefox does not display any style added in the above query (and that's correct), but the Chrome browse on 1280px screen size displays the style added in the above media query. Firefox不会显示在上述查询中添加的任何样式(正确),但是1280px屏幕尺寸的Chrome浏览器会显示在上述媒体查询中添加的样式。

Why Chrome on 1280px screen still displays the style added in the above media query? 为什么1280px屏幕上的Chrome仍显示上述媒体查询中添加的样式? How can I fix the above query for Chrome too? 我也该如何解决上述针对Chrome的查询? Thanks. 谢谢。

I'm really not sure why you're experience problems with your media query. 我真的不确定为什么您的媒体查询会遇到问题。 Perhaps you're not styling it properly. 也许您没有正确设置样式。

Obligatory JSFiddle here 强制性JSFiddle 在这里

body { background: red; }  
@media only screen and (min-width: 1024px) and (max-width: 1279px) {
    body { background: blue; }
}                                                         

I've tested it with Google Chrome on three different types of screen: 我已经在三种不同类型的屏幕上使用Google Chrome浏览器对其进行了测试:
1. A width of less than 1024px 1.宽度小于1024px
2. A width between the specified 1024px and 1279px 2.指定的1024像素和1279像素之间的宽度
3. A width of more than 1279px 3.宽度大于1279px

That is 6 years old but maybe help someone: 那是6岁,但也许可以帮助某人:

I was with this same problem, media queries working fine in edge and firefox but not in chrome. 我遇到了同样的问题,媒体查询在edge和firefox中工作正常,但在chrome中工作不正常。

The problem, in my case at least, was that I not put the viewport tag in head/html: 至少就我而言,问题是我没有将视口标签放在head / html中:

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

Now why the site was working in firefox/edge I don't know, actually make it harder to find the issue... 现在,为什么该网站在不知道的firefox / edge中工作,实际上使查找问题变得更加困难...

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

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