1

What I want to do is select <li> not having inside <ul>.

I tried with the selector above but it does not work.

.level1:not(:has(ul)) {
  background: red;
}
<ul>
  <li class="level1">Link1</li>
  <li class="level1">Link2
    <ul>
      <li>Link2</li>
    </ul>
  </li>
</ul>
dippas
  • 49,171
  • 15
  • 93
  • 105
Cristi
  • 470
  • 3
  • 15
  • because in my project structure this has to be done – Cristi Jan 26 '18 at 09:25
  • Yes, thats why you asked. But what is wrong with another approach? – Nico Haase Jan 26 '18 at 09:26
  • I dont't have control to change the approach in CSS and it's complicated to change now everything. I just need to select
  • that does not contain
    • – Cristi Jan 26 '18 at 09:29
    • 5
      I don't think it can be done without either changing the markup (adding classes) or using JS. CSS does not have a parent selector. – andeersg Jan 26 '18 at 09:41