小白教程
所有教程
关于
Search
172.70.131.102
172.70.131.102
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Sel last child”的源代码
本页内容
上一节:
Sel_nth_last_of_type
下一节:
Sel_root
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE::last-child}}[[Category:css selectors|36]] = CSS3 :last-child 选择器 = [[css selectors|完整CSS选择器参考手册]] 指定父元素中最后一个p元素的背景色: <sample title="" desc="" lang="html" hererun="1"> p:last-child { background:#ff0000; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p:last-child { background:#ff0000; } </style> </head> <body> <p>The first paragraph.</p> <p>The second paragraph.</p> <p>The third paragraph.</p> <p>The fourth paragraph.</p> </body> </html> </run> == 定义和用法 == :last-child 选择器用来匹配父元素中最后一个子元素。 '''提示:''' p:last-child 等同于 p:nth-last-child(1)。 == 浏览器支持 == 表格中的数字表示支持该属性的第一个浏览器版本号。 选择器 Chrome Internet Explorer / Edge Firefox Safari Opera :last-child 4.0 9.0 3.5 3.2 9.6 === 更多实例 === 指定父元素 ul 中最后一个 li 元素,并设置背景颜色: <sample title="" desc="" lang="html" hererun="1"> li:last-child { background-color: #ff0000; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> li:last-child { background-color: #ff0000; } </style> </head> <body> <ul> <li>此元素背景色不是红色。</li> <li>我的也不是红色。</li> <li>我的才是红色。</li> </ul> </body> </html> </run> [[css selectors|完整CSS选择器参考手册]]
返回至“
Sel last child
”。
上一节:
Sel_nth_last_of_type
下一节:
Sel_root