Trying to select only the top level UL element and exclude any nested UL elements in CSS. I've tried so many different variations but can't find a solution.
As an example, the html code could look like something below. Now I want to go ahead and style only the top level UL and don't apply the styling to the nested ULs. In my scenario, I can't add any classes or IDs to the HTML code - no changes to the HTML; CSS only.
<ul>
<li>
<ul>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
<li>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</li>
</ul>
I settled for *:not(li) > ul to only select top level <ul> elements and exclude <ul> elements that are inside of other <ul> elements.
Here's the most direct way of doing it:
ul:not(ul ul)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With