简体   繁体   English

@media Query可在IE,Firefox和Edge中使用,但不能在Chrome中使用

[英]@media Query Working in IE, Firefox, and Edge, but not Chrome

I have created a media query to shrink a div's (#example in this case) padding if the screen width goes below a certain point. 我创建了一个媒体查询来缩小div的填充(在这种情况下为#example),如果屏幕宽度低于特定点。 See the example below. 请参见下面的示例。

@media screen and (max-width: 733px) {
#example {
    padding-left: 90px;
    }
}

This query works perfectly in IE 11, Firefox Quantum, and Edge. 该查询可在IE 11,Firefox Quantum和Edge中完美运行。 However, when I test it in Chrome, I get the same result as if the query wasn't even there. 但是,当我在Chrome浏览器中对其进行测试时,即使没有查询,也会得到相同的结果。

After doing some research, I have added slight variations of a viewport entry in my HTML header, and at the moment my entry in <head></head> is: 经过研究后,我在HTML标头中添加了视口条目的细微变化,目前在<head></head>条目是:

<meta name="viewport" content="width=device-width" />

(I have also used "width=device-width, initial-scale=1" with no better result) (我也使用了“ width = device-width,initial-scale = 1”,但没有更好的结果)

Lastly, I have also tried using @media only screen instead of @media screen , and this has not worked either. 最后,我也尝试过使用@media only screen而不是@media screen ,但这也不起作用。

For some final details my html file is a cshtml file if it makes a difference (this is for a webapp), and I am testing through the VS2017 Community debugger. 对于一些最终细节,我的html文件是否有区别(这是针对webapp的)是cshtml文件,我正在通过VS2017社区调试器进行测试。

Thank you! 谢谢!

Your code is missing a brace "}". 您的代码缺少大括号“}”。 Below the correct code: 在正确的代码下面:

@media screen and (max-width: 733px) {
 #example {
    padding-left: 90px;
 }
}

Try adding this to your CSS : 尝试将其添加到您的CSS

@media screen and (max-width:733px),
    only screen and (-webkit-min-device-pixel-ratio: 2),
    only screen and (-moz-device-pixel-ratio: 2),
    only screen and (-o-min-device-pixel-ratio: 2/1),
    only screen and (min-device-pixel-ratio: 2),
    only screen and (min-resolution: 192dpi),
    only screen and (min-resolution: 2dppx)
   {
        #example
        {
            padding-left: 90px;
        }
   }

and this to the <head> section of the HTML document: 这是HTML文档的<head>部分:

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

This code is tested and works. 此代码已经过测试并且可以工作。 If it doesn't work for you, you might have problems somewhere else in your code, possibly your CSS . 如果对您不起作用,则您的代码中可能还有其他问题,可能是CSS In that case please post a link to your site or add some more code, preferably your CSS . 在这种情况下,请发布到您网站的链接或添加更多代码,最好是CSS

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

相关问题 JavaScript 在 Firefox、Chrome 中不起作用 - 在 IE、Edge 中有效 - JavaScript not working in Firefox, Chrome - works in IE, Edge 媒体查询只能在Chrome浏览器中使用,而不能在Safari(例如Firefox)中使用? - Media queries working in chrome but not safari, ie, or firefox? 媒体查询无法在Safari中工作,但在IE,Firefox和Chrome中 - Media queries not working in Safari but in IE, Firefox and Chrome 媒体查询不适用于Chrome和设备,但适用于Firefox - media query not working in chrome and device but working on firefox 我的网页中的媒体查询在 firefox、IE 和 Edge 浏览器中不起作用 - Media queries in my web page not working in firefox and IE and Edge browsers 我的媒体查询不适用于Google Chrome和Firefox - My Media Query is not working on google chrome and firefox 媒体查询不适用于 Firefox,但适用于 Chrome - Media query not working in Firefox but works in Chrome 标题在 IE 和 FIREFOX 中未正确显示(它在 Chrome 和 Edge 中工作) - Header is not showing correctly in IE and FIREFOX (it is working in Chrome and edge) Chrome可在Chrome,Opera和Edge上使用Javascript,但在FireFox或IE 11上则无法使用 - Javascript working on Chrome & Opera & Edge, but not on FireFox or IE 11 中心对齐导航栏与@media查询在Firefox和IE中不起作用 - Center aligning nav bar with @media query not working in Firefox and IE
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM