首页 - PHP编程

css实现表格奇偶行变色的方法

下面是使用 nth-child 伪类选择器的写法,通过表达式可以定义奇数行或偶数行!
nth-child(2n-1) //奇数行 
nth-child(odd) //奇数行 
nth-child(2n) //偶数行
nth-child(even) //偶数行
table表格奇数行变色的方法
table表格奇数行可以使用下面的CSS代码:
table tr:nth-child(2n-1){ background-color: red; }
table tr:nth-child(odd){ background-color: red; }
示例:
我是第二行
我是第三行
我是第四行
我是第五行
 
table表格偶数行变色的方法

table表格偶数行变行
table tr:nth-child(2n){ background-color: red; }
table tr:nth-child(even){ background-color: green; }
示例:
wfgk.net
我是第二行
我是第三行
我是第四行
我是第五行