Using the Specificity of :where() as a CSS Reset

As mentioned in Three important things you should know about CSS :is(), the specificity of :where() will always be 0: :where() works the same way like :is() does, but will always have a specificity of 0. You can cleverly wrap this around other selectors to undo their specificity. Think of :where(:not(…)) for example. Over at …


This content originally appeared on Bram.us and was authored by Bramus!

As mentioned in Three important things you should know about CSS :is(), the specificity of :where() will always be 0:

:where() works the same way like :is() does, but will always have a specificity of 0. You can cleverly wrap this around other selectors to undo their specificity. Think of :where(:not(…)) for example.

Over at CSS-Tricks, Mojtaba Seyedi details how we can also use this to do more clever CSS Resets

With the power of this selector, libraries can give us style with no specificity. So there would be no specificity to compete with when we as authors write CSS.

Like so:

:where(ul[class]) {
  list-style: none;
}

.list {
  list-style: square;
}

The contents inside :where() is specific enough to remove list-style only when a class is being used on an ul, while the use of :where() does not hinder any further overriding by the CSS developer.

Using the Specificity of :where() as a CSS Reset →


This content originally appeared on Bram.us and was authored by Bramus!


Print Share Comment Cite Upload Translate Updates
APA

Bramus! | Sciencx (2021-07-20T21:53:32+00:00) Using the Specificity of :where() as a CSS Reset. Retrieved from https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/

MLA
" » Using the Specificity of :where() as a CSS Reset." Bramus! | Sciencx - Tuesday July 20, 2021, https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/
HARVARD
Bramus! | Sciencx Tuesday July 20, 2021 » Using the Specificity of :where() as a CSS Reset., viewed ,<https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/>
VANCOUVER
Bramus! | Sciencx - » Using the Specificity of :where() as a CSS Reset. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/
CHICAGO
" » Using the Specificity of :where() as a CSS Reset." Bramus! | Sciencx - Accessed . https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/
IEEE
" » Using the Specificity of :where() as a CSS Reset." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/. [Accessed: ]
rf:citation
» Using the Specificity of :where() as a CSS Reset | Bramus! | Sciencx | https://www.scien.cx/2021/07/20/using-the-specificity-of-where-as-a-css-reset-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.