欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

@media 媒体查询

程序员文章站 2022-05-28 16:07:21
@media screen and (max-width: 300px) { //当视口宽度小于等于300px时生效 } max-width 相当于 <= @media screen and (min-width: 300px) { //当视口宽度大于等于300px时生效 } max-width 相 ......

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

    //当视口宽度小于等于300px时生效

}

 

max-width  相当于  <= 

 

@media screen and (min-width: 300px) {

    //当视口宽度大于等于300px时生效

}

 

max-width  相当于  >= 

 

@media screen and (min-windth:300px) and (max-width:600px) {

    //当视口宽度介于300px 和 600px 之间时生效

}

大于等于多少,小于等于多少的写法。

 

 

 

举例:

body{
    background: orange;
}
@media screen and (max-width:1200px) {
    body{
        background: green;
    }
}
@media screen and (max-width:1000px) {
    body{
        background: blue;
    }
}

起初,背景色是orange;

逐渐缩小视口到1200px,继续缩小,背景色变为green;

继续缩小至1000px,变为 blue。