!important在CSS中是什么意思? [英] What does !important mean in CSS?
问题描述
!important
在CSS中是什么意思?
在CSS 2中可用吗? CSS 3?
在哪里支持?所有现代的浏览器?
从本质上讲,它意味着什么;
这很重要,请忽略后续规则以及任何常见的特殊性问题,请应用此规则!"在正常使用中,外部样式表中定义的规则被文档的head
中定义的样式所取代,而该样式又被元素本身内的内联样式所取代(假设选择器).用!important
'attribute'(?)定义规则将放弃关于后继"规则取代早先"规则的常规顾虑.
通常,更具体的规则将覆盖较不具体的规则.所以:
a {
/* css */
}
通常由以下规则否定:
body div #elementID ul li a {
/* css */
}
由于后一个选择器更具体(通常,在哪里找到更具体的选择器(在 但是,如果将 使用 这也使调试CSS成为一场噩梦(来自个人,经验和经验). What does Is it available in CSS 2? CSS 3? Where is it supported? All modern browsers? It means, essentially, what it says; that 'this is important, ignore subsequent rules, and any usual specificity issues, apply this rule!' In normal use a rule defined in an external stylesheet is overruled by a style defined in the Also, ordinarily, a more specific rule will override a less-specific rule. So: Is normally overruled by: As the latter selector is more specific (and it doesn't, normally, matter where the more-specific selector is found (in the If, however, you add Using It also makes debugging your CSS a nightmare (from personal, empirical, experience). 这篇关于!important在CSS中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!head
或外部样式表中)并不重要,它将仍然覆盖较不特定的选择器(内嵌样式属性将始终覆盖'more-'或'less-'特定选择器,因为它始终更具体.
!important
添加到不太特定的选择器的CSS声明中,它将具有优先级.!important
有其目的(尽管我很难想到它们),但这很像使用核爆炸来阻止狐狸杀死您的鸡;是的,狐狸将被杀死,鸡也将被杀死.还有邻居.!important
mean in CSS?head
of the document, which, in turn, is overruled by an in-line style within the element itself (assuming equal specificity of the selectors). Defining a rule with the !important
'attribute' (?) discards the normal concerns as regards the 'later' rule overriding the 'earlier' ones.a {
/* css */
}
body div #elementID ul li a {
/* css */
}
head
or the external stylesheet) it will still override the less-specific selector (in-line style attributes will always override the 'more-', or the 'less-', specific selector as it's always more specific.!important
to the less-specific selector's CSS declaration, it will have priority.!important
has its purposes (though I struggle to think of them), but it's much like using a nuclear explosion to stop the foxes killing your chickens; yes, the foxes will be killed, but so will the chickens. And the neighbourhood.