我有使用内联样式的标记,但我没有权限更改此标记。如何仅使用CSS覆盖文档中的内联样式?我不想使用jQuery或JavaScript。
HTML:
<div style="font-size: 18px; color: red;">
Hello World, How Can I Change The Color To Blue?
</div>
CSS:
div {
color: blue;
/* This Isn't Working */
}
发布于 2013-06-24 19:08:33
除了内联!important
样式之外,您可以很容易地覆盖内联样式
所以
<div style="font-size: 18px; color: red;">
Hello World, How Can I Change The Color To Blue?
</div>
div {
color: blue !important;
/* This will Work */
}
但是如果你有
<div style="font-size: 18px; color: red !important;">
Hello World, How Can I Change The Color To Blue?
</div>
div {
color: blue !important;
/* This Isn't Working */
}
现在它将仅为red
..你不能重写它
发布于 2014-08-26 14:37:27
<div style="background: red;">
The inline styles for this div should make it red.
</div>
div[style] {
background: yellow !important;
}
以下是更多详细信息的链接:http://css-tricks.com/override-inline-styles-with-css/
发布于 2019-12-26 17:24:07
CSS属性中使用的!important
<div style="color: red;">
Hello World, How Can I Change The Color To Blue?
</div>
div {
color: blue !important;
}
https://stackoverflow.com/questions/16813220
复制相似问题