:nth-of-type(n)选择器匹配同类型中的第n个同级兄弟元素。
n可以是一个数字,一个关键字,或者一个公式。
p:nth-of-type(2) { background:#ff0000; }
HTML
<h1>This is a heading</h1> <p>The first paragraph.</p> <p>The second paragraph.</p> <p>The third paragraph.</p> <p>The fourth paragraph.</p>
CSS
p:nth-of-type(2) { background:#ff0000; }
执行结果
The first paragraph.
The second paragraph.
The third paragraph.
The fourth paragraph.