仅针对父母李而不是具有CSS的孩子

时间:2019-03-13 10:07:21

标签: css css3 css-selectors

我想定位父级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>

1 个答案:

答案 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>