小白教程
所有教程
关于
Search
172.70.178.89
172.70.178.89
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Sel nth last of type”的源代码
本页内容
上一节:
Sel_nth_of_type
下一节:
Sel_last_child
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE::nth-last-of-type(n)}}[[Category:css selectors|35]] = CSS3 :nth-last-of-type() 选择器 = [[css selectors|完整CSS选择器参考手册]] 指定每个p元素匹配同类型中的倒数第2个同级兄弟元素背景色: <sample title="" desc="" lang="html" hererun="1"> p:nth-last-of-type(2) { background:#ff0000; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p:nth-last-of-type(2) { 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> <p><b>注意:</b> Internet Explorer 8以及更早版本的浏览器不支持:nth-last-of-type() 选择器.</p> </body> </html> </run> == 定义和用法 == :nth-last-of-type(n)选择器匹配同类型中的倒数第n个同级兄弟元素。 n 可以是一个数字,一个关键字,或者一个公式。 '''提示:'''请参阅:[[sel nth last child|:nth-last-child()]]选择器。该选择器匹配父元素中的倒数第n个结构子元素 == 浏览器支持 == 表格中的数字表示支持该属性的第一个浏览器版本号。 {| class="table table-striped table-hover" ! 选择器 ! Chrome ! Internet Explorer / Edge ! Firefox ! Safari ! Opera |- | :nth-last-of-type() | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |} == 更多实例 == == 实例 1 == 奇数和偶数是可以作为关键字使用用于相匹配的子元素,其索引是奇数或偶数。 在这里,我们为奇数和偶数的倒数p元素指定两个不同的背景颜色: <sample title="" desc="" lang="html" hererun="1"> p:nth-last-of-type(odd) { background:#ff0000; } p:nth-last-of-type(even) { background:#0000ff; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p:nth-last-of-type(odd) { background:#ff0000; } p:nth-last-of-type(even) { background:#0000ff; } </style> </head> <body> <p>The first paragraph.</p> <p>The second paragraph.</p> <p>The third paragraph.</p> <p><b>注意:</b> Internet Explorer 8以及更早版本的浏览器不支持:nth-last-of-type() 选择器.</p> </body> </html> </run> == 实例 2 == 使用公式(an+ b).描述:a代表一个循环的大小,N是一个计数器(从0开始),以及b是偏移量。 在这里,我们对所有索引是3的倍数的倒数顺序的p元素指定了背景颜色: <sample title="" desc="" lang="html" hererun="1"> p:nth-last-of-type(3n+0) { background:#ff0000; } </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</title> <style> p:nth-last-of-type(3n+0) { 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> <p>The fifth paragraph.</p> <p>The sixth paragraph.</p> <p>The seventh paragraph.</p> <p>The eight paragraph.</p> <p>The ninth paragraph.</p> <p><b>注意:</b> Internet Explorer 8以及更早版本的浏览器不支持 :nth-last-of-type()选择器.</p> </body> </html> </run> [[css selectors|完整CSS选择器参考手册]]
返回至“
Sel nth last of type
”。
上一节:
Sel_nth_of_type
下一节:
Sel_last_child