我想定位父级li,而不是仅使用css选择器定位子级li。
<ul>
<li>{Target the li of this ul only}</li>
<li>{Target the li of this ul only}</li>
<li>
<ul>
<li>{it would be different styling}</li>
<li>{it would be different styling}</li>
<li>{it would be different styling}</li>
</ul>
</li>
</ul>
答案 0 :(得分:2)
同时给两个孩子上不同的班级,并给他们的孩子li应用风格
.a>li {
color: green
}
.b>li {
color: red
}
<ul class='a'>
<li>{Target the li of this ul only}</li>
<li>{Target the li of this ul only}</li>
<li>
<ul class='b'>
<li>{it would be different styling}</li>
<li>{it would be different styling}</li>
<li>{it would be different styling}</li>
</ul>
</li>
</ul>