什么时候CSS的!重要的声明不工作? [英] When does CSS's !important declaration not work?

查看:90
本文介绍了什么时候CSS的!重要的声明不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人可以在CSS中的的重要声明中加入一些权威的参考摘要来覆盖内联样式。

I am wondering if someone can put a bit of an authoritative reference summary of when the !important declaration in CSS does not work to override inline styles.

推荐答案

确定哪些样式相互重叠有很多因素。 级联中显示的样式声明越低,并且更具体定位到元素,则其对其他样式的权重越大。

There are many factors involved in determining which styles override one another. The lower a style declaration appears in the cascade, and the more specific it is in targeting the element, the more it will weigh against other styles.

这是 CSS2标准的样式继承:



  1. 如果级联产生值,请使用它。

  2. 否则,如果属性是继承的,请使用父元素
    元素的值,通常是计算的值。

  3. 否则使用属性的初始值。
    每个属性的初始值在
    属性的定义中指示。


在内部,浏览器将计算规则的特异性,根据标准。 !important声明将为规则增加权重,但是动态分配样式属性通常会优先,因为它通常指定更高。

Internally, the browser will calculate the specificity of a rule, according to the standard. The !important declaration will add weight to the rule, but dynamically assigning a style attribute will often take precedence, because it is usually more-highly specified..

这篇关于什么时候CSS的!重要的声明不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆