CodeNewbie Community

Discussion on: Is there a CSS parent selector?

Collapse
alvaro_montoro profile image
Álvaro Montoro • Edited on

There isn't an explicit parent selector, but in the CSS selectors of level 4, it is defined the :has() pseudo-class which allows to select an element based on the selectors passed to the :has(). That would allow to select an element based on their children, providing a "parent" selector (e.g. div:has(> img) would select the div that is a direct parent of an img)... Unfortunately, it is not supported by any browser at the moment.