In CSS (any version), is there something like, or any other way of doing anything like the :has() selector in jQuery?
jQuery(':has(selector)')Description: Selects elements which
contain at least one element that
matches the specified selector.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, there isn’t. The way CSS is designed, does not permit selectors that match ancestors or preceding siblings; only descendants (
and>), succeeding siblings (~and+) or specific children (:*-child). The only ancestor selector is the:rootpseudo-class which selects the root element of a document (in HTML pages, naturally it would behtml).If you need to apply styles to the element you’re querying with
:has(), you need to add a CSS class to it then style by that class, as suggested by Stargazer712.