CSS !important 规则

什么是!important

!importantCSS 中的规则用于为属性/值增加比正常情况更重要的重要性。

事实上,如果您使用该!important规则,它将覆盖该元素上该特定属性的所有先前样式规则!

让我们看一个例子:

<!DOCTYPE html>
<html>
<head>
<style>
#myid {
  background-color: blue;
}

.myclass {
  background-color: gray;
}

p {
  background-color: red !important;
}
</style>
</head>
<body>

<p>This is some text in a paragraph.</p>

<p class="myclass">This is some text in a paragraph.</p>

<p id="myid">This is some text in a paragraph.</p>

</body>
</html>

效果如下: