我对表格使用even& oddCSS 规则,但这也是不断变化的 <thead>。
thead {background-color: #999;}
tr:nth-child(even) {background: #fff}
tr:nth-child(odd) {background: #C8C8C8}
结果是我的 <thead> is#C8C8C8和 not #999。
所以我的问题是,是否可以在不影响 <thead> 的情况下使用偶数和奇数?
我对表格使用even& oddCSS 规则,但这也是不断变化的 <thead>。
thead {background-color: #999;}
tr:nth-child(even) {background: #fff}
tr:nth-child(odd) {background: #C8C8C8}
结果是我的 <thead> is#C8C8C8和 not #999。
所以我的问题是,是否可以在不影响 <thead> 的情况下使用偶数和奇数?
您可以添加tbody到您的选择器,以便该规则仅适用于您的 tbody 中的 tr:s:
tbody tr:nth-child(even) {background: #fff}
tbody tr:nth-child(odd) {background: #C8C8C8}
当然,使用tbody选择器:
thead{background-color: #999;}
tbody tr:nth-child(even) {background: #fff}
tbody tr:nth-child(odd) {background: #C8C8C8}
因为您在 上使用<tbody>元素<table>,对吗?如果没有,你应该使用它:)