html css odd,html - CSS Odd/Even td nested - Stack Overflow

本文讨论了在CSS中为表格行应用odd/even样式时遇到的问题。由于直接在row上设置背景色在某些浏览器中可能导致不一致的结果,作者建议将样式应用于td/th元素。然而,这种方法在处理嵌套场景时会出现问题。文章提出了理想的解决方案,即使用CSS子选择器,但指出这在旧版浏览器中可能不适用。
摘要由CSDN通过智能技术生成

I am trying to come up with a style my rows with odd/even styles. The row is going to be marked with class odd/even but the style needs to apply to the containing td/th.

The reason the style can't be placed directly on the row is because applying background colors to the row instead of the td/th causes inconsistent results in certain browsers.

When I apply the color to the td/th it causes problem in nested scenarios.

Nesting

.even td, .even th {

background-color: #FBFCFD;

}

.odd td, .odd th {

background-color: #FEFFFF;

}

TestTest
TestTest
TestTest
Test
TestTest
TestTest
TestTest
Test
TestTest
TestTest
TestTest
TestTest

What would be ideal is if I could do something like the following, but unfortunately it does work in older browsers.

.even > td, .even > th {

background-color: #FBFCFD;

}

.odd > td, .odd > th {

background-color: #FEFFFF;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值