css3媒体查询

发布于:2022-07-26 ⋅ 阅读:(247) ⋅ 点赞:(0)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            width: 500px;
            height: 500px;
            background-color: #ccc;
            transition: 1s;
        }
        .box1{
            width: 500px;
            height: 500px;
            background-color: #ccc;
            transition: 1s;
        }
        @media screen and (min-width:800px) {
            .box{
                background-color: red;
            }
        }
        @media screen and (min-width:1200px) {
            .box{
                background-color: blue;
            }
        }
        /* min-width从小到大
        max-width从大到小 */
        @media screen and (max-width:1500px) {
            .box1{
                background-color:rebeccapurple;
            }
        }
        @media screen and (max-width:1100px) {
            .box1{
                background-color:green;
            }
        }
        @media screen and (max-width:900px) {
            .box1{
                background-color: hotpink;
            }
        }
        @media screen and (max-width:700px) {
            .box1{
                background-color: darkred;
            }
        }
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="box1"></div>
</body>
</html>