什么是重要的CSS意味着什么

什么是重要的CSS意味着什么

本文介绍了什么是重要的CSS意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

in CSS是什么意思?

它是用于css2,css3,IE吗?

What does !important in CSS mean?
Is it for css2, css3, IE only?

推荐答案

这意味着,

在正常使用中,定义的规则是:外部样式表被在文档的中定义的样式所覆盖,而该样式又被元素本身内的内联样式推翻(假设等式的选择器)。使用!important 'attribute'(?)定义一个规则会丢弃关于'later'规则覆盖'较早'规则的正常问题。

In normal use a rule defined in an external stylesheet is overruled by a style defined in the 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.

此外,通常,更具体的规则将覆盖较少特定的规则。所以:

Also, ordinarily, a more specific rule will override a less-specific rule. So:

a {
    /* css */
}

通常被推翻:

body div #elementID ul li a {
    /* css */
}

由于后面的选择器更具体(并且通常不会发生更具体的选择器 head 或外部样式表)将会仍然覆盖较少特定的选择器(内嵌样式属性将始终 >重写more-或less-特定选择器,因为它总是更具体。

As the latter selector is more specific (and it doesn't, normally, matter where the more-specific selector is found (in the 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 添加到less特定选择器的CSS声明中,它将具有优先权。

If, however, you add !important to the less-specific selector's CSS declaration, it will have priority.

使用!important 有它的目的(虽然我很难想到他们),但它很像使用核爆炸阻止狐狸杀死你的鸡;是的,狐狸会被杀死,但鸡也是如此。

Using !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.

这也使你的CSS调试成为噩梦(从个人,经验和经验)。

It also makes debugging your CSS a nightmare (from personal, empirical, experience).

这篇关于什么是重要的CSS意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:44