Making content-aware components using CSS :has(), grid, and quantity queries – Piccalilli

October 30, 2024

One of the real strengths of web components is encapsulation–a component is by default (largely) sealed off from the DOM it is embedded in–global CSS doesn’t inherit, or cascade, into the component (caveats for CSS custom properties, slots).

Which is also a kind of weakness–since there are times you will want the global style inherited.

Here Eric Baily explores using modern CSS features that aid in creating components that are self-aware, and display themselves nicely no matter where they might be placed.