CodeNewbie Community 🌱

Gwene
Gwene

Posted on

Is there a CSS parent selector?

I've been working on upping my CSS skills lately and came across of the question whether or not there are CSS parent sectors - and I haven't been able to figure this one out.

Anyone got some wisdom to impart?

Top comments (2)

Collapse
 
alvaro_montoro profile image
Álvaro Montoro • Edited

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.

Collapse
 
ender_minyard profile image
ender minyard

No, there is no CSS parent selector.

css-tricks.com/parent-selectors-in...