简体   繁体   English

媒体查询不适用于指定查询

[英]Media query doesn't work on specified query

When I set my style for a certain detect type, instead of using that media style at the designated media detected width, it uses it as a parent value which I don't understand why it's doing that. 当我将样式设置为某种检测类型时,不是在指定的检测到的媒体宽度上使用该媒体样式,而是将其用作父值,我不知道为什么这样做。

Fiddle without said style applied: http://jsfiddle.net/T6Sk4/ works normally 未使用上述样式的小提琴: http : //jsfiddle.net/T6Sk4/正常工作

Fiddle with it applied to specific width: http://jsfiddle.net/T6Sk4/1/ hmm.. 小提琴将其应用于特定的宽度: http//jsfiddle.net/T6Sk4/1/ hmm ..

@media (min-width: 320px) {
    #contain {
        width:300px;
    }
    .box {
        display:none;
    }
}
@media (min-width: 480px) {
    #contain {
        width:460px;
    }
}
@media (min-width: 600px) {
    #contain {
        width:580px;
    }
}
@media (min-width: 760px) {
    #contain {
        width:740px;
    }
}
@media (min-width: 900px) {
    #contain {
        width:880px;
    }
}
@media (min-width: 1038px) {
    #contain {
        width:980px;
    }
}

Ok. 好。 Change your code for 480px with the following code. 使用以下代码将代码更改为480px It is working fine in all the screens without the 320px screen. 在没有320px屏幕的所有屏幕上,它都能正常工作。 I have tested. 我测试过了 So try this and let me know: 因此,请尝试让我知道:

@media only screen and (min-width: 480px) {
 #contain {
    width:460px;
 }
.box {
    display:block;
 }
}

Also you should use your code like this way @media only screen and (min-width:480px){} for all the screens. 另外,您应该像这样使用代码,即@media only screen and (min-width:480px){}用于所有屏幕。 If don't understand check my code. 如果不明白,请检查我的代码。

最小宽度大于320px像素,因此每次匹配时都会应用每个媒体查询。

if you want to improve performance and readability, add max-width values too. 如果要提高性能和可读性,也可以添加最大宽度值。 At the moment, all of your rules are used on large screens, overwriting the same rule quite often. 目前,您的所有规则都在大屏幕上使用,经常覆盖同一规则。 The second benefit: you know exactly which rule applies. 第二个好处:您确切知道哪个规则适用。

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

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