!important语法和描述

!important为开发者提供了一个增加样式权重的方法。应当注意的是!important是对整条样式的声明,包括这个样式的属性和属性值。

#example {
  font-size: 14px !important;    
}

#container #example {
  font-size: 10px;
}    

实例说明:

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

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    .div1 {
        color: red !important;
        /*color: red;*/
    }
    
    #div1 {
        color: blue;
        font-weight: bold;
    }
    </style>
</head>

<body>
    <div class="div1" id='div1' style='color:green;'>
        <p>div1内容</p>
        <span>span中的内容</span>
    </div>
</body>

</html>
View Code

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2021-08-17
  • 2022-12-23
  • 2021-10-26
  • 2021-11-22
  • 2021-08-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
相关资源
相似解决方案