Controlling inheritance
CSS provides four special universal property values for controlling inheritance:
- inherit : to be the same as that of its parent element
- initial : to the initial value of that property
- unset : acts like inherit, otherwise it acts like initial
- revert : new feature
The CSS shorthand property all
can be used to apply one of these inheritance values to (almost) all properties at once.
It's a convenient way to undo changes made to styles so that you can get back to a known starting point before beginning new changes.
Specificity
The amount of specificity a selector has is measured using four different values (or components), which can be thought of as thousands, hundreds, tens and ones — four single digits in four columns.
**Thousands**: Score one in this column if the declaration is inside a style attribute, aka **inline styles**. Such declarations don't have selectors, so their specificity is always simply 1000.
**Hundreds**: Score one in this column for each **ID selector** contained inside the overall selector.
**Tens**: Score one in this column for each **class selector**, **attribute selector**, or **pseudo-class** contained inside the overall selector.
**Ones**: Score one in this column for each **element selector** or **pseudo-element contained inside the overall selector**.
Note: The universal selector (*), combinators (+, >, ~, ' '), and negation pseudo-class (:not) have no effect on specificity.
!important
仅仅用在非常特殊的情况,可以强制修改前面所描述所有规则。
用法:border: none !important;
如果两个规则都用了!importance
则对比规则的先后顺序和specificity
仅仅作为一种知识的补充,但是并不推荐大家使用这个方法,除非当你无法修改CSS代码的时候可以考虑。
网友评论