CSS - 表行的背景颜色奇/偶 [英] CSS - background color of table row odd/even

查看:96
本文介绍了CSS - 表行的背景颜色奇/偶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由PHP动态生成的表。我希望我可以使用CSS应用背景颜色基于表行是奇/偶,即背景颜色旋转每隔一行。

I have a table that is dynamically generated by PHP. I am hoping that I can use CSS to apply a background color based on where the table row is odd/even, i.e. the background color rotates every other row.

合理?
谢谢!

Does that make sense? Thanks!

推荐答案

您可以使用 nth-of-type() nth-child() CSS3中的选择器。受所有现代浏览器支持。

You can use the nth-of-type() or nth-child() selector in CSS3. Supported by all modern Browsers.

例如...

tr:nth-child(odd) { background-color: #ccc; }

/* Do this… */
tr:nth-of-type(odd) { background-color: #ccc; }

/* …or this */
tr:nth-of-type(even) { background-color: #ccc; }

这篇关于CSS - 表行的背景颜色奇/偶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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