How does CSS specificity decide which styles to apply?

后端 未结 3 1795
春和景丽
春和景丽 2020-12-03 22:52

How does CSS determine when to apply one style over another?

I have been through the W3 CSS3 selectors document a few times, and that has helped me understand how to

3条回答
  •  萌比男神i
    2020-12-03 23:54

    http://www.w3.org/TR/CSS21/cascade.html#specificity is the official specificity specification.

    But if that's TL;DR, the (too) short version is the more words you have in your selector, the higher the specificity. And with !important even higher. That's about it.

    Edit: oh, I see that your link has the same information as mine. Sorry about that.

提交回复
热议问题