美文网首页
CSS Building Block -- Cascade an

CSS Building Block -- Cascade an

作者: 忻恆 | 来源:发表于2020-08-19 02:32 被阅读0次

    Controlling inheritance

    CSS provides four special universal property values for controlling inheritance:

    1. inherit : to be the same as that of its parent element
    2. initial : to the initial value of that property
    3. unset : acts like inherit, otherwise it acts like initial
    4. 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.

    1. **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.
      
    2. **Hundreds**: Score one in this column for each **ID selector** contained inside the overall selector.
      
    3. **Tens**: Score one in this column for each **class selector**, **attribute selector**, or **pseudo-class** contained inside the overall selector.
      
    4. **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代码的时候可以考虑。

    相关文章

      网友评论

          本文标题:CSS Building Block -- Cascade an

          本文链接:https://www.haomeiwen.com/subject/hyzodktx.html