1、:nth-child(n)、:nth-last-child(n)
p:nth-child(2) {……}
菜鸟教程解释:选择所有p元素的第二个子元素
但给的例子实现中,我认为应该解释为:改变第二个元素且元素为p的样式。若p父元素的第二个子元素不是p,那么这个样式无效。而不是教程中所说的所有p元素的第二个子元素。
p:nth-last-child(2){……} 改变倒数第2个且元素为p的样式.
2、:first-of-type
p:first-of-type :选择p的父元素的所有子元素的第一个p
如下面例子,第一个父元素是div,第二个是body。
<div>
<p>The first paragraph.</p>
<p>The third paragraph.</p>
</div>
<h1>This is a heading</h1>
<p>The first paragraph.</p>
<p>The third paragraph.</p>
3、:nth-of-type(n)
p:nth-of-type(2) 选择所有p元素中第二个为p的子元素
4、:only-of-type
p:only-of-type 选择所有仅有一个子元素为p的元素