P粉7040660872023-08-24 10:03:55
You can use :has()
CSS pseudo-class
But it has limited browser support (currently not supported by Firefox).
P粉0113609032023-08-24 09:39:22
There is currently no way to select the parent element of an element in CSS in a way that works in all browsers.
Selector Level 4 Working Draft Includes :has()
Pseudo class that will provide this functionality. It would be similar to the jQuery implementation, but is currently not supported by Firefox.
li:has(> a.active) { /* styles to apply to the li tag */ }
Firefox is currently the only major browser that does not support it by default.
Meanwhile, if you need to select a parent element with full cross-browser support, you'll have to resort to JavaScript in Firefox.