“Sel nth last of type”的版本间差异
本页内容
(创建页面,内容为“{{DISPLAYTITLE::nth-last-of-type(n)}}13 = CSS3 :nth-last-of-type() 选择器 = 完整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>小白教程(xia…”) |
无编辑摘要 |
||
(未显示同一用户的1个中间版本) | |||
第1行: | 第1行: | ||
{{DISPLAYTITLE::nth-last-of-type(n)}}[[Category:css | {{DISPLAYTITLE::nth-last-of-type(n)}}[[Category:css selectors|35]] | ||
= CSS3 :nth-last-of-type() 选择器 = | = CSS3 :nth-last-of-type() 选择器 = | ||
第55行: | 第55行: | ||
{| class="table table-striped table-hover" | {| class="table table-striped table-hover" | ||
! 选择器 | ! 选择器 | ||
! | ! Chrome | ||
! | ! Internet Explorer / Edge | ||
! | ! Firefox | ||
! | ! Safari | ||
! | ! Opera | ||
|- | |- | ||
| :nth-last-of-type() | | :nth-last-of-type() |
2022年8月19日 (五) 04:50的最新版本
CSS3 :nth-last-of-type() 选择器
指定每个p元素匹配同类型中的倒数第2个同级兄弟元素背景色:
示例
p:nth-last-of-type(2)
{
background:#ff0000;
}
定义和用法
- nth-last-of-type(n)选择器匹配同类型中的倒数第n个同级兄弟元素。
n 可以是一个数字,一个关键字,或者一个公式。
提示:请参阅::nth-last-child()选择器。该选择器匹配父元素中的倒数第n个结构子元素
浏览器支持
表格中的数字表示支持该属性的第一个浏览器版本号。
选择器 | Chrome | Internet Explorer / Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
:nth-last-of-type() | 4.0 | 9.0 | 3.5 | 3.2 | 9.6 |
更多实例
实例 1
奇数和偶数是可以作为关键字使用用于相匹配的子元素,其索引是奇数或偶数。
在这里,我们为奇数和偶数的倒数p元素指定两个不同的背景颜色:
示例
p:nth-last-of-type(odd)
{
background:#ff0000;
}
p:nth-last-of-type(even)
{
background:#0000ff;
}
实例 2
使用公式(an+ b).描述:a代表一个循环的大小,N是一个计数器(从0开始),以及b是偏移量。
在这里,我们对所有索引是3的倍数的倒数顺序的p元素指定了背景颜色:
示例
p:nth-last-of-type(3n+0)
{
background:#ff0000;
}