gpt4 book ai didi

internet-explorer - CSS3 On IE8 奇偶行不同颜色

转载 作者:行者123 更新时间:2023-12-04 07:42:33 31 4
gpt4 key购买 nike

我正在编写用于通过不同颜色区分奇数行和偶数行的 Css 代码

.historyLog tr:nth-child(odd) td {
background-color:blue;
}
.historyLog tr.odd td{
background-color: blue;
}

.historyLog tr:nth-child(even) td {
background-color:orange;
}
.historyLog tr.even td{
background-color: orange;
}

并且有类 .historyLog 的表

<table class="historyLog">
<tr><td></td></tr>
<tr><td></td></tr>
</table>

我的问题是,当我使用类属性 .historyLog i.ie 应用 Css 时

.historyLog tr:nth-child(odd) td {
background-color:blue;
}

IE8 不执行它,我将得到的是所有行的相同颜色,无论是偶数行还是奇数行。但是,如果我在不使用表的类属性的情况下应用 css,即

tr:nth-child(odd) td {
background-color:blue;
}

然后IE8在奇偶行用不同的颜色执行。请帮助我给出IE8如何使用表格的类属性以不同颜色显示奇数行和偶数行的答案。

最佳答案

因为 IE8 不支持 CSS3 选择器。您可以很好地使用 jQuery 的内置 :odd 或 :even 选择器来实现相同的功能。

$(".historyLog tr:odd").css('background-color','blue');
$(".historyLog tr:even").css('background-color','white');

或者你可以改用css类文件

$(".historyLog tr:odd").addClass("odd");
$(".historyLog tr:even").addClass("even");

关于internet-explorer - CSS3 On IE8 奇偶行不同颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12105275/

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