H5Skills icon indicating copy to clipboard operation
H5Skills copied to clipboard

快速理解nth-child和nth-of-type的异同

Open beidan opened this issue 7 years ago • 0 comments

  1. nth-child是根据元素个数来计算,比如:p:nth-child(1) 是表示这是个p元素,且这是父标签的第二个孩子元素,2个条件都必须满足才会生效

  2. nth-of-type。比如:p:nth-child(3) 选中p元素的第3个元素

  3. 从下面的例子可以清晰地看到nth-child和nth-of-type的区别

   p:nth-of-type(3){color:red;}
   p:nth-child(2) {color:blue;}
   p:nth-child(3) {color:blue;}
2

beidan avatar Jul 05 '17 07:07 beidan