I have a HTML structure as shown below
<ul class="list list--sm">
<li class="list__item list__item--draggable">
List item 1
<ul>
<li class="list__item list__item--draggable">
List item 1.1
<ul>
<li class="list__item list__item--draggable">
List item 1.1.1
</li>
</ul>
</li>
</ul>
</li>
</ul>
Here I want to target the elements with class list__item--draggable
that do not have a parent/grandparent with the class list__item--draggable
i.e. the element with the text "List item 1". I want to achieve this using LESS. I do not want to use the > selector because it can be a nested structure with few more divs and other elements.
I am not able to think of a solution for this. Can this be achieved?
2
Answers
This is possible even in pure CSS:
Try it:
It may depend on exactly how you want to style/restyle the children but here’s a simple CSS example which highlights just that first text:
Basically, we change every occurence, then we change back those that are children.