目录

:nth-of-type()

: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;
}

执行结果

This is a heading

The first paragraph.

The second paragraph.

The third paragraph.

The fourth paragraph.

参考

相关页面

外部链接