:nth-last-child()

:nth-last-of-type(n)选择器匹配同类型中的倒数第n个同级兄弟元素。

n可以是一个数字,一个关键字,或者一个公式。

 

语法

p:nth-last-child(2)
{
background:#ff0000;
}

例子

HTML

<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>

CSS

p:nth-last-child(2)
{
	background:#ff0000;
}

执行结果

The first paragraph.

The second paragraph.

The third paragraph.

The fourth paragraph.

参考

相关页面

外部链接