其实区别很简单::nth-of-type为什么要叫:nth-of-type?因为它是以”type”来区分的。也就是说:ele:nth-of-type(n)是指父元素下第n个ele元素,
而ele:nth-child(n)是指父元素下第n个元素且这个元素为ele,若不是,则选择失败。
<div>
<ul class="demo">
<p>zero</p>
<li>one</li>
<li>two</li>
</ul>
</div>
1
2
3
4
5
6
7
8
上面这个例子,.demo li:nth-child(2)选择的是<li>one</li>节点,而.demo li:nth-of-type(2)则选择的是<li>two</li>节点
---------------------
作者:强哥blog
来源:CSDN
原文:https://blog.csdn.net/qq_36263601/article/details/74180472
版权声明:本文为博主原创文章,转载请附上博文链接!
浙公网安备 33010602011771号