brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: :is() shortens long css selector lists, but it takes the highest specificity

Css
~/tips/tip-css-is-selector-list-specificity

.post :is(h2, h3, h4) { margin-block-start: 2rem; }

Groups several selectors into one short expression, with the specificity of the strongest entry.

Writing the same prefix five times in a stylesheet is tedious and easy to get wrong.

.post :is(h2, h3, h4) { margin-block-start: 2rem; }
:is(ul, ol) :is(ul, ol) { margin-block: 0; }

:is() expands to the full list of selectors, so the first rule replaces three separate ones. If one entry in the list is an ID, the whole :is() gets the specificity of that ID, because the most specific argument decides. The list is also forgiving: an invalid entry is skipped instead of breaking the whole rule, which is not true for a normal comma list. Use :where() when you want zero specificity instead.

Further reading: MDN: :is()

More Css tips CSS Overview in Chrome DevTools audits the colors and fonts of a page .notice:empty { .toast { article { counter-reset: h2; } .toolbar { All Css tips (66) All topics

Link