0

How we can apply CSS to a li which contains a particular class on children/sub-children with CSS only. For example, we have

<li>
  <div class='custom-class-1'>
    Alex
  </div>
</li>
<li>
  <div class='custom-class-2'>
    Alex
  </div>
</li>

So in this case, We want to apply a style to li which has a div with class custom-class-2, so in above example style will be applied on second li only.

Alex
  • 1,406
  • 2
  • 18
  • 33
  • 1
    you can't. You would need to select the aprent of a certain class and CSS has no parent selector. Your only chance is to skip that appraoch and use `nth-child` or `nth-of-type` unless you can manipulate the HTML markup and add a class directly. – tacoshy Jun 15 '22 at 16:23
  • 1
    https://developer.mozilla.org/en-US/docs/Web/CSS/:has Come back in a few years for this to be a thing. – Lee Taylor Jun 15 '22 at 16:28

0 Answers0