- HTML中文网
- 联系QQ:88526
- QQ交流群

- 微信公众号

:nth-of-type()选择器
含义和使用:
:nth-of-type(n)选择器匹配同类型中的第n个同级兄弟元素。
n可以是一个数字,一个关键字,或者一个公式。
浏览器支持:
选择器 | ![]() | ![]() | ![]() | ![]() | ![]() |
:nth-of-type() | 9.0 | 3.5 | 9.6 | 4.0 | 3.2 |
CSS语法:
:nth-last-of-type(n){ CSS语法;}
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> p:nth-last-of-type(2) { background:pink; } </style> </head> <body> <h1>元素1</h1> <p>元素2</p> <p>元素3</p> <p>元素4</p> </body> </html>
点击 "运行实例" 按钮查看在线实例
效果图:
推荐手册