H5Skills
H5Skills copied to clipboard
快速理解nth-child和nth-of-type的异同
-
nth-child是根据元素个数来计算,比如:p:nth-child(1) 是表示这是个p元素,且这是父标签的第二个孩子元素,2个条件都必须满足才会生效。
-
nth-of-type。比如:p:nth-child(3) 选中p元素的第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;}
