CSS3 伪类nth-child
来源:互联网 发布:淘宝图片跟买家秀 编辑:程序博客网 时间:2024/05/02 00:21
nth-child(),是CSS3中的一个伪类选择符。这里介绍的是 nth-child() 的语法和用法:语法: :nth-child(an+b) 描述:伪类:nth-child()的参数是an+b
举例用法
tr:nth-child(2n+1)
tr:nth-child(odd)
tr:nth-child(2n)
tr:nth-child(even)
第一种:简单数字序号写法
:nth-child(number)
直接匹配第number个元素。参数number必须为大于0的整数。
例子:
li:nth-child(3){background:orange;}
第二种:倍数写法
:nth-child(an)
匹配所有倍数为a的元素。其中参数an中的字母n不可缺省,它是倍数写法的标志,如3n、5n。
例子:
li:nth-child(3n){background:orange;}
第三种:倍数分组匹配
:nth-child(an+b) 与 :nth-child(an-b)
先对元素进行分组,每组有a个,b为组内成员的序号,其中字母n和加号+不可缺省,位置不可调换,这是该写法的标志,其中a,b均为正整数或0。如3n+1、5n+1。但加号可以变为负号,此时匹配组内的第a-b个。
例子:
li:nth-child(3n+1){background:orange;}
li:nth-child(3n+5){background:orange;}
li:nth-child(5n-1){background:orange;}
li:nth-child(3n±0){background:orange;}
li:nth-child(±0n+3){background:orange;}
第四种:反向倍数分组匹配
:nth-child(-an+b)
此处一负一正,均不可缺省,否则无意义。这时与:nth-child(an+1)相似,都是匹配第1个,但不同的是它是倒着算的,从第b个开始往回算,所以它所匹配的最多也不会超过b个。
例子:
li:nth-child(-3n+8){background:orange;}
li:nth-child(-1n+8){background:orange;}
第五种:奇偶匹配
:nth-child(odd) 与 :nth-child(even)
分别匹配序号为奇数与偶数的元素。奇数(odd)与(2n+1)结果一样;偶数(even)与(2n+0)及(2n)结果一样。
衍生伪类
•E:nth-last-child(n): 选择某个子元素,从最后一个数起
•E:nth-of-type(n): 选择某个某种类型的子元素
•E:nth-last-of-type(n): 选择某个某种类型的子元素,从最后一个符合条件的元素数起
•E:first-child: 选择第一个子元素(这个伪类在CSS2里就有)
•E:last-child: 选择最后一个子元素
- CSS3 伪类nth-child
- CSS3伪类选择器:nth-child()
- CSS3伪类选择器:nth-child()
- CSS3 :nth-child()伪类选择器
- CSS3伪类选择器:nth-child()
- CSS3 :nth-child()伪类选择器
- CSS3 :nth-child()伪类选择器
- CSS3 伪类选择器 nth-child()说明
- CSS3 :nth-child()伪类选择器
- CSS3 :nth-child()伪类选择器
- CSS3伪类选择器:nth-child()
- web CSS3伪类选择器 :nth-child()
- CSS3:nth-child()伪类选择器…
- CSS3 :nth-child()伪类选择器
- css3:nth-child()伪类选择器
- [转]CSS3 :nth-child()伪类选择器
- 【CSS3】结构性伪类选择器—nth-child(n)
- 【CSS3】结构性伪类选择器—nth-last-child(n)
- C++想记就记
- 关于joomla模板兼容问题
- __declspec关键字详细用法
- 在Style Report中如何制作多层表头的交叉报表
- MTK多国语言相关经验总结
- CSS3 伪类nth-child
- XML文件中nbsp的产生和问题解决
- 类函数指针的动态映射(回调函数)
- Linux下vi命令大全
- 三思笔记,涂抹ORACLE~~
- Datagrid数据导出到excel文件的三种方法
- apache 自动停止运行
- apache 自动停止2
- Datagrid数据导出到excel文件的三种方法