CSS3 :last-of-type 选择器
实例
指定父元素的最后一个 p 元素的背景色:
<!DOCTYPE html><html><head><style>p:last-of-type {background: #ff0000;}</style></head><body><h2>这是一个标题</h2><p>第1个段落。</p><p>第2个段落。</p><p>第3个段落。</p><p>第4个段落。</p></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 选择器 | |||||
|---|---|---|---|---|---|
| :last-of-type | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
定义和用法
:last-of-type 选择器匹配属于其父元素的特定类型的最后一个子元素的每个元素。
提示:等同于 :nth-last-of-type(1)。
CSS 语法
:link {css declarations;}