dotancohen dotancohen - 1 year ago 66
CSS Question

Filter CSS selector based on child properties

Given that there are no parent selectors in CSS and even in Python one must resort to XML to get to parent elements, how might one target the

element which contains the
<span class="foo">

<li><span class="bar">John</span></li>
<li><span class="bar">Paul</span></li>
<li><span class="foo">George</span></li>
<li><span class="bar">Ringo</span></li>

This is in CSS: no Javascript, jQuery, Selenium, or Ford Pantera in the environment.

Answer Source

At the moment, you can't.

CSS Selectors Level 4 has a new selector :has

MDN Reference :has

The :has() CSS pseudo-class represents an element if any of the selectors, relative to the:scope of the given element, passed as parameters, matches at least one element. The :has() pseudo-class takes a selector list as an argument.

In your case it would be

`li:has( {}`

At present though, no broswer supports this selector.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download