Open wang1dot0 opened 5 years ago
两者都是伪类选择器,直接看例子
<div class="container"> <p>This is the first sentence</p> <p>This is the second sentence</p> </div>
这里p::nth-child(2)与p::nth-of-type(2)无差别,都是第二个p标签 但是我们变更一下
p::nth-child(2)
p::nth-of-type(2)
<div class="container"> <span>This is a span.</span> <p>This is the first sentence</p> <p>This is the second sentence</p> </div>
这里p::nth-child(2)与p::nth-of-type(2)就大大的不同了,nth-child(2)会选中第一个p标签,而nth-of-type(2)依旧选择第二个p标签。 总结:
具有BFC特性的元素可以看作隔离了的独立容器,容器里面的元素不会在布局上影响外部的元素,并且BFC具有普通容器所没有的一些特性。
nth-child 与 nth-of-type的区别
两者都是伪类选择器,直接看例子
这里
p::nth-child(2)
与p::nth-of-type(2)
无差别,都是第二个p标签 但是我们变更一下这里
p::nth-child(2)
与p::nth-of-type(2)
就大大的不同了,nth-child(2)会选中第一个p标签,而nth-of-type(2)依旧选择第二个p标签。 总结: