ul, ul ul, ul ul ul {
list-style: none;
margin: 0;
padding: 0;
}
Question: is there selector, so I can use it to apply style for each n-deep ul?
For example:
ul > ul
ul, ul ul, ul ul ul {
list-style: none;
margin: 0;
padding: 0;
}
Question: is there selector, so I can use it to apply style for each n-deep ul?
For example:
ul > ul
On
The properties you are applying are usually resets what we do on ul element, so writing something like
ul {
//Reset properties
}
is more than enough to get it applied across the dom at any level.
Still for some reason if you want to target specific properties at specific levels you need to use > but make sure you cannot write which is wrong as you cannot nest a ul > ulul element as a direct child to a ul.
So if you want to specifically target ul and not the general reset than use a wrapper element around first level of your ul and use a selector like
.wrapper ul {
//targets all ul nested under .wrapper
}
For starters, the selector
ul > ulwill not work asulelements may not be direct children of otherulelements. You'd need to useul > li > ulin this instance.What you can do to target specific depth levels is root everything to the first
ulelement's parent. For example, if your top-levelulwas a direct child of thebodyelement, you can simply addbody >into your selectors:For what it's worth though, with the correct specificity the selector
ulalone would be enough to apply the style to all yourulelements (if you're not wanting to just target specific depth levels).A standalone selector to target a specific depth unfortunately does not exist. Perhaps you're approaching this in the wrong way though - why don't you add a
classoridattribute to the specificulyou wish to style and use them as the selector instead?