!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>