0

I'm trying to select an element having a descendant with CSS.

Basically if I have a

<div id="looking_for_this">
  <ul>
    <li>
      <div class="must_have_this_class">text</div>
    </li>
  </ul>
</div>
<div id="looking_for_this_too">
  <ul>
    <li>
      <div class="must_have_this_class">other text</div>
    </li>
  </ul>
</div>

I'm looking to find the divs (I marked them with an id) based on the fact that they have a descendant with a class: must_have_this_class.

I found the experimental pseudo-class :has(), which I would use like:

 div:has(.must_have_this_class) { ... }  

finding the two divs in the example. Though this is an experimental feature, and no browsers support it as of Oct 2018.

Don Giulio
  • 2,393
  • 3
  • 35
  • 64

0 Answers0