我有一个结构:
<div id="div">
<ul class="ul">
<li class="li_one">
</li>
<li class="li_two">
</li>
</ul>
</div>
我想使用伪选择器设置background:red第二个元素(“li_two”类),并希望从最外层的 div 开始。li我正在尝试这种方式:
#div > ul:nth-child(1) { background:red; } // works but wrong, sets background to ul
#div ul:last-child { background:red; } // doesn't set to any element
#div ul:first-child { background:red; } // again sets to ul but not to li
#div [class=li_two] { background:red; } // only this one works fine
是否可以将样式设置li_two为#div使用:nth-child或:last-child或:first-child选择器?怎么做?