返回到:CSS 伪类(Pseudo-classes) | CSS教程
定义和用法
:last-of-type选择器匹配元素其父级是特定类型的最后一个子元素。
提示: 和:nth-last-of-type(1)是一个意思。
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
| 选择器 | 谷歌 | IE | 火狐 | 苹果 | opera |
|---|---|---|---|---|---|
| :last-of-type | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
实例
指定其父级的最后一个p元素的背景色:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web176教程(web176.com)</title>
<style>
p:last-of-type
{
background:#ff0000;
}
</style>
</head>
<body>
<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>
</body>
</html>作者:terry,如若转载,请注明出处:https://www.web176.com/cssprop/5364.html
支付宝
微信