gpt4 book ai didi

html - 具有备用背景行和标题的表格

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:00 24 4
gpt4 key购买 nike

我使用 css 使我的行像这样交替: Fiddle

tr:nth-child(odd) td   { background-color:red; }
tr:nth-child(even) td { background-color:blue; }
tr th { background-color: yellow}

table {
border: 1px solid black;
margin: 10px;
width: 100px;
}

有些表格有标题,有些表格没有。数据总是需要以红色开头,但是当表格有标题时,它的行被算作第一行,数据以蓝色开头。有没有办法让它总是以红色开头?

最佳答案

使用<tbody><thead>

使用 <tbody>并将所有 body 行放入其中。另外,将标题包装在 <thead> 中.更新了下面的 CSS:

tbody tr:nth-child(odd) td   { background-color:red; }
tbody tr:nth-child(even) td { background-color:blue; }
thead tr th { background-color: yellow}

这样您将只定位数据行而不是标题行。希望这对你有帮助...

fiddle :http://jsfiddle.net/praveenscience/TQgjC/

关于html - 具有备用背景行和标题的表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14410606/

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