奇数和偶数行上的不同CSS样式 [英] Different CSS style on odd and even rows

查看:249
本文介绍了奇数和偶数行上的不同CSS样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有使用CSS,才能为动态生成的表设置奇数和偶数行的不同样式,而无需在迭代集合时为每行设置正确的样式。

Is it possible, using only CSS, to set different styles on odd and even rows for a dynamically generated table without myself setting correct style on each row when I iterate the collection?

推荐答案

我不确定这将工作的跨浏览器,我更喜欢jQuery自己,但css只有这应该做的诀窍:

I'm not sure this will work cross-browser, i'd prefer jQuery myself, but css-only this should do the trick:

tr:nth-child(even) { ... }
tr:nth-child(odd) { ... }

这篇关于奇数和偶数行上的不同CSS样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆