Media query: how to make text change color when window width gets below 600px

心已入冬 提交于 2019-12-11 19:31:28

问题


I want to make my text change color when the window size gets below 600px:

jsfiddle: http://jsfiddle.net/LgsXT/1/

text:

<div class = "derp">derp derp derp</div>

css:

.derp {
color:red;
}

@media (max-width:600) {
    .derp {
        color:blue;
    }
}

But it's not doing anything. What's wrong?


回答1:


You need a px or other unit for the @media rule. Also, watch those spaces in your HTML, and I would suggest you work up instead of down in screen-size

<div class="my-box">Derp</div>


.my-box {
    color: red;
}

@media (min-width: 600px) {

    .my-box {
        color:blue;
    }

} /* end break point */

Here is a more robust fiddle




回答2:


You need to add a unit to your value in the query otherwise the number has no meaning so it would look like this:

.derp {
    color:red;
}

@media (max-width:600px) {
    .derp {
        color:blue;
    }
}


来源:https://stackoverflow.com/questions/22442274/media-query-how-to-make-text-change-color-when-window-width-gets-below-600px

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