代码实例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> li:last-child { background:#ff0000; } </style> </head> <body> <ul> <li>The first paragraph.</li> <li>The second paragraph.</li> <li>The third paragraph.</li> <li>The fourth paragraph.</li> </ul> </body> </html>
尝试一下 »
点击“尝试一下”按钮查看在线实例
定义和用法
:last-child选择器用来匹配父元素中最后一个子元素。
提示: p:last-child等同于p:nth-last-child(1)。