1.使用nth-child和nth-last-child时会产生的问题

在使用nth-child和nth-last-child时,其计算子元素是奇数个元素还是第偶数个元素时,是连同父元素中的所有子元素一起计算的。

当父元素是列表时,列表中只可能有列表项目一种子元素,所以不会出问题,但是当父元素是div时,div包含多种子元素,会出现问题。

2.使用nth-of-type和nth-last-of-type

<style type="text/css">

h2:nth-of-type(odd){

   background:yellow;

}

h2:nth-of-type(even){

  background:blue;

}

</style>

//只计算h2元素的,而不会包含和h2同级别的其他元素

 

相关文章:

  • 2021-11-24
  • 2022-02-02
  • 2021-07-17
  • 2021-10-07
  • 2021-12-14
  • 2021-07-13
  • 2021-07-22
猜你喜欢
  • 2021-04-13
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-11-10
  • 2022-12-23
  • 2021-08-18
相关资源
相似解决方案