如果是复合选择器,则会有权重叠加,需要计算权重。

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>Document</title>
    8. <style>
    9. ul li {
    10. color: blue;
    11. }
    12. li {
    13. color: red;
    14. }
    15. </style>
    16. </head>
    17. <body>
    18. <ul>
    19. <li>权重的叠加</li>
    20. </ul>
    21. </body>
    22. </html>

    效果图
    image.png
    ul li 的权重:0,0,0,1 + 0,0,0,1 = 0,0,0,2
    li的权重:0,0,0,1
    所以是最终是blue色。

    <!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>
        ul li {
          color: blue;
        }
    
        .abc li {
          color: red;
        }
      </style>
    </head>
    
    <body>
      <ul class="abc">
        <li>权重的叠加</li>
      </ul>
    </body>
    
    </html>
    

    image.png

    )
    ul li 的权重是:0,0,0,2
    .abc li 的权重是:0,0,1,0 + 0,0,0,1 = 0,0,1,1
    比ul li 的权重大
    所以是red颜色。

    需要注意的是:虽然权重可以叠加,但是永远不会进位。
    例如:
    0,0,0,1+ ,,,, + 0,0,0,1 = 0,0,0,100
    不能进位为0,1,0,0,它还是它,还是0,0,0,100
    还是比0,0,1,0的权重小。