media query in css

白昼怎懂夜的黑 提交于 2019-12-13 18:25:59

问题


How do I write media query only for 1024px width?

Here is my existing css which i have written for 320px width and more

@media (min-width: 320px) {

} 

What is the method for only 1024px width?


回答1:


I believe you want this:

@media (min-width: 320px) and (max-width: 1023px) {
    /* styles for width > 320px but < 1023px */
}


@media (min-width: 1024px) {
 /* styles for width > 1024px only */
}

this way you do not have to override any styles.

otherwise you can do that:

@media (min-width: 320px) {
    /* styles for width > 320px - applied to width > 1024px too */
}


@media (min-width: 1024px) {
 /* styles for width > 1024px only */
}

that is different in the way that you will have to override your first media query styles when needeed, in the second one




回答2:


I think if you just want 1024, not 1023 or less, or 1025 or more, you could do

@media (width: 1024px) {
    ....
 }

The min/max prefixes are optional. See the w3 entry on it.




回答3:


Write like this:

@media (max-width:1024px) {
 body{..}

} 

Check this http://jsfiddle.net/YhsSK/



来源:https://stackoverflow.com/questions/11050633/media-query-in-css

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