问题描述
如果您有
< div style =display:none!important;>< / div&是否有一种方法可以在样式表中覆盖它以使其显示?
b
$ b 最好使用类似这样的东西:
div {display:block!important; }
解决方案内容样式可覆盖:
.override {color:red!important;}
< p style =color:blue;>我会是蓝色< / p> ;
< p style =color:blue; class =override>但我会是红色< / p>
此行为描述于中,其中声明!important
不改变特异性,而是优先于正常声明。
也就是说,当冲突规则都有!important
标志时,应用 - 意味着对于OP的情况,没有办法重写内联 !important
。
If you have
<div style="display: none !important;"></div>
Is there a way to override that in the style sheet to make it displayed?
Preferably using something similar to this:
div { display: block !important; }
解决方案 Let me begin by saying that generally inline styles can be overridden:
.override {color:red !important;}
<p style="color:blue;">I will be blue</p>
<p style="color:blue;" class="override">But I will be red</p>
This behavior is described in W3 specs, where it is stated that !important
declarations do not alter the specificity, but rather take precedence over "normal" declarations.
That being said, when conflicting rules both have the !important
flag, specificity dictates that an inline rule is applied - meaning that for OP's scenario, there's no way to override an inline !important
.
这篇关于我可以覆盖内联!重要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!