如何在html表上创建斑马条纹,而不使用javascript和偶/奇类生成?
问题描述:
我想斑马条纹的html表,不使用任何js的东西或编写服务器端代码来生成表/行的偶/奇类。
I want to zebra-stripe a html table without using any js stuff or writing server-side code to generate even/odd classes for table rows. Is it ever possible to do using raw css?
答
这是可能的,但只能使用CSS3选择器:
It is possible, but only with CSS3 selectors:
tr:nth-child(even) {
background-color: red;
}
tr:nth-child(odd) {
background-color: white;
}
现代浏览器已支持它。