:has() selector
:has() selector
As browser support for the :has() selector grows, front-end devs will finally have a CSS-only approach for parent selectors. For example, let’s say you have a paragraph with the class .child and you want to style the parent DIV:
div:has(> p.child) {
border: 2px solid #000;
}
This basic example will apply a 2px black border around the parent DIV. Keep in mind, full support is not quite there yet in all major browsers so use this trick cautiously.