gpt4 book ai didi

php - CSS - 表行奇数/偶数的背景颜色

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:18 24 4
gpt4 key购买 nike

我有一个由 PHP 动态生成的表。我希望我可以使用 CSS 根据表格行的奇数/偶数位置应用背景颜色,即背景颜色每隔一行旋转一次。

这有意义吗?谢谢!

最佳答案

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

例如……

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; }

关于php - CSS - 表行奇数/偶数的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4836134/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com