选择符层叠性的总结

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
        }
        
        #wrap {
            height: 600px;
        }
        
        div {
            background: orange!important;
        }
    </style>
</head>

<body>
    <div class="box" id="wrap" style="background: red;"></div>
</body>

</html>

 

<!-- 
    只要产生权重关系,必然体现css的层叠性
    权重高的覆盖权重低的
    如果权重相同,后写的会把前写的覆盖掉

    权重比较:
        内联样式表  >   id  >   class  >    类型选择符
        !important 权重最高
        
        div {
            background: orange!important;
        }

 -->
posted on 2021-01-04 15:20  sunandwang  阅读(72)  评论(0)    收藏  举报