如何在 HTML 中显示表格正文?
在 HTML 中使用 <tbody> 标签来显示表格正文。HTML <tbody> 标签用于向表格添加正文。tbody 标签与 thead 标签和 tfoot 标签结合使用,用于确定表格的每个部分(标题、页脚、正文)。以下是 <tbody> 标签的属性−
属性 |
值 |
说明 |
|---|---|---|
align |
Right left center justify char |
Deprecated − 视觉对齐。 |
char |
字符 |
Deprecated − 指定在哪个字符上对齐文本。当 align="char" 时使用 |
charoff |
像素或 % |
已弃用 − 指定一个对齐偏移量(以像素或百分比值为单位),针对用 char 属性指定的第一個字符。当 align="char" 时使用 |
valign |
Top middle bottom baseline |
已弃用 − 垂直对齐。 |
示例
以下是示例,在 HTML 中显示表格正文 –
<!DOCTYPE html>
<html lang="en">
<head>
<title>html</title>
<style>
table {
border-collapse: collapse;
}
td,
th {
border: 3px solid red;
}
thead {
color: blue;
}
tfoot {
background-color: yellow;
}
</style>
</head>
<body>
<table>
<caption align="bottom">World Cup Tennies</caption>
<!--Caption*/ -->
<tbody>
<thead>
<tr>
<th rowspan="2">Date</th>
<th colspan="2">Final Match</th>
<th rowspan="2">Location</th>
<tr>
<th>Team A</th>
<th>Team B</th>
</tr>
</thead>
<tr>
<td>20-10-2022</td>
<td>India</td>
<td>England</td>
<td>Australia</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="2">Final Score</th>
<th>India - 1</th>
<th>England - 0</th>
</tr>
</tfoot>
</table>
</body>
</html>
示例
以下示例演示如何在 HTML 中显示表格正文 −
<!DOCTYPE html>
<html>
<head>
<title>HTML tbody Tag</title>
</head>
<body>
<table style="width:100%" border="1">
<thead>
<tr>
<td colspan="4">This is the head of the table</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4">This is the foot of the table</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
<tr> Each row containing four cells... </tr>
</tbody>
<tbody>
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</tbody>
</table>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP