media query in css

2019-08-09 00:07发布

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?

3条回答
小情绪 Triste *
2楼-- · 2019-08-09 00:48

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楼-- · 2019-08-09 01:08

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

查看更多
\"骚年 ilove
4楼-- · 2019-08-09 01:08

Write like this:

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

} 

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

查看更多
登录 后发表回答