gpt4 book ai didi

html - CSS HTML tfoot、tbody、thead 复杂样式

转载 作者:行者123 更新时间:2023-11-28 16:03:20 27 4
gpt4 key购买 nike

我可以使用 <thead> 吗?里面<tbody><tfoot>除了主要<thead><table>

我想在主要组件中设置不同的 thead 样式,但我不明白,为什么更高规范的组件中的一些没有反应,而有些样式适用于每个 <tr>虽然我只将它指定给 <tbody> .

我想尝试不上课。

这是一个简单的例子:

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {
background-color: black;
text-align: center;
color: black;
}

table > thead {background-color: pink;} /*0002 - to main thead*/
table > tbody > thead > tr > th {background-color: skyblue; } /*0005 - to "Final students marks" and "Avarage marks in groups"*/


tbody > tr:nth-child(even) {background: #CCC;} /*0011*/
tbody > tr:nth-child(odd) {background: #FFF;} /* why it styling tfoot?? */

tfoot tr:nth-child(even) {background: sandybrown !important; /*why not work???*/ }
tfoot tr:nth-child(odd) {background: sandybrown !important;}
</style>
</head>
<body>
<table>
<thead>
<tr><th>Number</th><th>Name</th><th>Surname</th><th>Group</th><th>Mark</th></tr>
</thead>

<tbody>
<thead><tr><th colspan="5">Final students marks</th></tr></thead>

<tr><td>1</td><td>Adam</td><td>Abacki</td><td>A</td><td>4</td></tr>
<tr><td>2</td><td>Ewa</td><td>Babacka</td><td>B</td><td>5</td></tr>
<tr><td>3</td><td>Edward</td><td>Cabacki</td><td>A</td><td>3</td></tr>
<tr><td>4</td><td>Tomasz</td><td>Dadacki</td><td>A</td><td>4</td></tr>
<tr><td>5</td><td>Anna</td><td>Kowalska</td><td>B</td><td>3</td></tr>
<tr><td>6</td><td>Marek</td><td>Zawadzki</td><td>A</td><td>5</td></tr>
</tbody>

<tfoot>
<thead><tr><th colspan="5">Average marks in groups</th></tr></thead>

<tr><td>1</td><td colspan="2"></td><td>A</td><td>4</td></tr>
<tr><td>2</td><td colspan="2"></td><td>B</td><td>4</td></tr>
</tfoot>
</table>

</body>
</html>

这是我想要的最终效果: Expected look of table

最佳答案

<thead>

Permitted content: Zero or more <tr> elements.

Permitted parents: A <table> element.

所以你的表结构应该是:

table
thead
tr
th
tbody
tr
td
tfoot
tr
td

body {
text-align: center;
}

table {
width: 100%;
border: 1px solid black;
border-spacing: 0;
}

table>thead {
background-color: pink;
font-weight: bold;
}

table>tbody>tr:first-child>td,
table>tfoot>tr:first-child>td {
font-weight: bold;
background-color: skyblue;
}

tbody>tr:nth-child(odd) {
background: #CCC;
}

tfoot>tr {
background: sandybrown;
}

tbody>tr>td:first-child,
tfoot>tr>td:first-child {
background: yellow;
}
<body>
<table>
<thead>
<tr>
<th>Number</th>
<th>Name</th>
<th>Surname</th>
<th>Group</th>
<th>Mark</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="5">Final students marks</td>
</tr>
<tr>
<td>1</td>
<td>Adam</td>
<td>Abacki</td>
<td>A</td>
<td>4</td>
</tr>
<tr>
<td>2</td>
<td>Ewa</td>
<td>Babacka</td>
<td>B</td>
<td>5</td>
</tr>
<tr>
<td>3</td>
<td>Edward</td>
<td>Cabacki</td>
<td>A</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>Tomasz</td>
<td>Dadacki</td>
<td>A</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>Anna</td>
<td>Kowalska</td>
<td>B</td>
<td>3</td>
</tr>
<tr>
<td>6</td>
<td>Marek</td>
<td>Zawadzki</td>
<td>A</td>
<td>5</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="5">Average marks in groups</td>
</tr>
<tr>
<td>1</td>
<td colspan="2"></td>
<td>A</td>
<td>4</td>
</tr>
<tr>
<td>2</td>
<td colspan="2"></td>
<td>B</td>
<td>4</td>
</tr>
</tfoot>
</table>

关于html - CSS HTML tfoot、tbody、thead 复杂样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53326449/

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