I have the following CSS code:
article ul ul :nth-child(2) {
border:1px solid black;
}
Which selects every second element in the dom tree, regardless of the depth in tree. (but it has to be inside an ul
, which has to be inside of an ul
, which has to be inside of an article
).
But why does this not select every second item in this example?
article ul ul :nth-child(2) {
border: 1px solid black;
}
<article>
<ul>
<li>this not</li>
<li>this not</li>
<ul>
<li>this not</li>
<li>this</li>
<p>
<li>this not</li>
<li>why not this?</li>
</p>
</ul>
</ul>
</article>
But when I change the p
element to a div
it works. Can somebody explain this?