mediaqueries max-width not working in firefox

一个人想着一个人 提交于 2020-01-06 16:17:13

问题


I want to use a mediaquerie for max-width. It works fine with Chrome but in Firefox it does not, why?

jsfiddle code

CSS

.box {
    width: 150px;
    height: 150px;
    background-color: blue;
}

@media screen and(max-width: 400px){    
    .box {
        background-color: red;
    }
}

回答1:


Your syntax is wrong, you need a space between and(max-width)

See below

@media screen and (max-width: 400px){
    .box {
        background-color: red;
    }
}

JSFIDDLE




回答2:


There is no closing bracket in your above @media rule -

.box{
    width: 150px;
    height: 150px;
    background-color: blue;
}

@media screen and (max-width: 400px){

    .box{
        background-color: red;
    }

} /* END THIS @MEDIA RULE */

I like to do something really obvious like this to remind me --- You don't need the "and" - or the "screen"

@media (min-width: 30em){ /* ============ */

    body {
        background-color: red;
    }

} /* === END MEDIUM BREAK =============== */


来源:https://stackoverflow.com/questions/16866595/mediaqueries-max-width-not-working-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!