CodeNewbie Community 🌱

Regina
Regina

Posted on

Is there a CSS parent selector?

Hello! This is my first post here on the CodeNewbie Forem and I'm kicking it off with a very beginner question. I'd love your thoughts!

Is there any way to select the parent of an element in CSS only?

Thanks 🙏

Top comments (4)

Collapse
 
murkrage profile image
Mike Ekkel

Currently there is no way of doing that with just CSS, unfortunately. There is a working draft for the ‘has()’ pseudo-class that does what you are looking for, but browser support is just not there. Read more about it here: developer.mozilla.org/en-US/docs/W...

In the meantime: what are you trying to achieve?

Collapse
 
reggie_hazel profile image
Regina

Thank you so much for this response! I'm trying to work with a menu via a CMS and I can't move the active element to

  • — at least not easily.

    This is helpful, though :)

  • Collapse
     
    eineki profile image
    Eineki

    Like @murkrage said, you can't do it at the present.

    If you need to style an element when one of his children is focused there is an handy pseudo-class you can actually use. It is supported in all major browser (maybe all)
    You can read more about it here:
    developer.mozilla.org/en-US/docs/W...

    Collapse
     
    reggie_hazel profile image
    Regina

    Thank you!!

    Some comments may only be visible to logged-in visitors. Sign in to view all comments.