!important 已覆盖
我正在使用 JQuery mobile,我希望我的应用程序上的所有文本都是紫色的。我在 css 的 body
部分中执行了以下操作: color: #7A68AE !important;
。
然后我尝试在 firebug 中调试它,并注意到我的 !important
被覆盖。
这怎么可能?难道 !important
不应该覆盖其他所有内容吗?
注意我已经解决了这个问题,我只是很好奇为什么 !important
不起作用
I am using JQuery mobile and I want all of the text to be purple on my application. I did this: color: #7A68AE !important;
in my body
section of my css.
I then tried to debug it in firebug and noticed that my !important
was overridden.
How is this possible? Isn't !important
supposed to overwrite everything else?
Note I have already fixed the problem, I was just really curious about why !important
didn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看有关特异性的规范。虽然
!important
应该被覆盖,但内联样式可能会因为它所承载的权重而覆盖它。然而,在没有看到例子的情况下,我不能百分百肯定。
另请参阅!重要规则
Take a look at the spec on specificity. Though
!important
should override, it's possible an in-line style may override this due to the weight it carries.Without seeing an example I can't be 100% positive, however.
See Also !important rules
!important 确实会覆盖同一层次结构级别的任何内容——但是带有 !important 声明的用户样式表是无与伦比的。
完整的继承体系是
链接样式表< head 中的嵌入样式 <在文档样式块中(受影响的元素之前)<内嵌样式(降价)元素内样式 (style="" attr)
这就是为什么它们被称为级联记录样式表
因此,带有 !important 声明的链接样式表,就像您可以看到,这毕竟不是那么重要。
Firebug 在其许多工具(例如突出显示 div/链接等)中使用带有 !important 的动态用户声明。
尝试在不使用 Firebug 的情况下进行查看。如果这改变了它,它的萤火虫就会改变它
!important does over ride anything at the same hierarchy-level -- but a user's style sheet with an !important declaration is like unbeatable.
The full heirarchy is
linked style sheet < embeded styles in head < in doc style block (before affected element) < in-line style (depriciated) < in-element style (style="" attr)
This is why they are called Cascading Style Sheets for the record
So a linked style sheet with an !important declaration, as you can see, isn't all THAT !important after all.
Firebug uses on-the-fly user declarations with !important for alot of its tools (such as highlight divs/links/etc.)
Try viewing without Firebug. If that changes it, its firebug transforming it
发生这种情况的原因可能有很多。例如:
!important
子句被另一个!important
子句覆盖,并具有更具体的选择器(编辑:回答您问题的其他人之一,Brad,指出了一个资源关于它: www.w3.org/TR/CSS2/cascade.html#specificity< /a>),您说您有Firebug,所以您应该能够确定是什么情况。请参阅启用和禁用 JS 的情况,查看应用于特定选择器的样式并查看生成的样式。如果没有代码,我们对此无话可说。
This might have happened because of many reasons. For example:
!important
clause was overriden by another!important
clause, with more specific selector (Edit: one of other people answering your question, Brad, pointed a resource about it: www.w3.org/TR/CSS2/cascade.html#specificity),You said you have Firebug, so you should be able to determine what is the case. See with JS enabled and disabled, see styles applied for specific selectors and see resulting styles. Without the code there is not much we can say about that.