Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSS Specificity

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

CSS Specificity

Avatar for Matija Marohnić

Matija Marohnić

October 09, 2020
Tweet

More Decks by Matija Marohnić

Other Decks in Programming

Transcript

  1. A little bit about me • frontend developer and blogger

    • obsessed with generating static sites • DX evangelist • open source • automate all the things • follow me on Twitter: @silvenon
  2. MDN Web docs “Specificity is the means by which browsers

    decide which property values are the most relevant to an element and, therefore, will be applied.”
  3. 0 54 0 type selectors, pseudo-elements class selectors, attribute selectors,

    pseudo-classes ID selectors A trick to bump specificity
  4. • these don’t affect specificity: • universal selector (*) •

    combinators (+, >, ~, etc.) • negation pseudo-class (:not())
  5. 1 0 0 0 type selectors, pseudo-elements class selectors, attribute

    selectors, pseudo-classes ID selectors inline style
  6. 1 0 0 0 1 type selectors, pseudo-elements class selectors,

    attribute selectors, pseudo-classes ID selectors inline style !important
  7. When to use !important • as little as possible •

    basically only to override third-party styles
  8. • the lower the specificity, the easier it is to

    manage • plus, this way we keep repetition out of HTML …source order.