<body>

<style type="text/css">

//只对li1设置样式

li:nth-child(1):nth-last-child(1){

   background:yellow;

}

</style>

<h2>列表1</h2>

<ul>

  <li>li1</li>

</ul>

<h2>列表2</h2>

<ul>

<li>li1</li>

<li>li2</li>

</ul>

</body>

另外:可以直接使用

li:only-child{

   background:yellow;

}

来达到相同的目的。

相关文章:

  • 2022-12-23
  • 2021-08-12
  • 2021-07-09
  • 2021-12-18
  • 2021-10-12
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2022-01-08
  • 2021-11-09
相关资源
相似解决方案