li > ul > li
selects all li
elements which are deeper than the first level of a ul
.
li
selects all li elements
li:not(li > ul > li)
should select all li
elements which are no deeper than the first level of a ul
--that is, only first level elements--but it doesn't. Why?
Thanks!
Id selector has highest priority because of unique nature of the ID attribute definition. We have two classes with one ID selector here it will apply font-size:12px and font-weight:500 due to the specificity rule as ID selector has highest priority after inline CSS.
To specify the style for a list, use the list-style property to specify the type of marker. The selector in your CSS rule can either select the list item elements li , or it can select the parent list element ul so that its list elements inherit the style.
The first selector (“ ul ”) still selects all <ul> elements, whether they have a class or not. Classes can be added as you find you need them to make the appearance of the page match your intent.
The reason li:not(li > ul > li)
does not work is because the li > ul > li
is not a simple selector (as Felix Kling noted in the comments to your question).
The easiest way to get the top level is to give a class or id to the outer most ul
and then do:
.ulClassNameOrID > li {}
However, the following gets what you desire also (see fiddle) as it does not select any ul
that is a direct child of a previous li
(so is not a sublist of the outer list):
:not(li) > ul > li {}
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