Specificity rules for comma delineated lists

前端 未结 4 874
眼角桃花
眼角桃花 2020-12-18 12:05

When using Cascading Style Sheets I have observed the order of specificity as follows:

1st Laws: In-line Styles
2nd Laws: Numbe

4条回答
  •  旧时难觅i
    2020-12-18 12:26

    Remember that CSS is cascading - meaning the style that is referenced FURTHER down a CSS file will take precedence assuming the selector is the same:

    header {
      background-color: red;
    }
    p, span, header {
      background-color: yellow;
    }
    HEADER

    If we switch around the declarations above, the opposite happens:

    p, span, header {
      background-color: yellow;
    }
    header {
      background-color: red;
    }
    HEADER

    As you can see, comma separated selectors / declaration make no difference - they're treated the same as if you'd done them singly.

提交回复
热议问题