覆盖内联样式的唯一方法是使用!important
CSS规则旁边的关键字。以下是一个示例。
div {
color: blue !important;
/* Adding !important will give this rule more precedence over inline style */
}
<div style="font-size: 18px; color: red;">
Hello, World. How can I change this to blue?
</div>
重要笔记:
。因此,您应避免同时使用!important
内联样式。
将!important
关键字添加到任何CSS规则后,该规则就可以 于该元素的 。
它甚至会覆盖 标记中的内联样式。