如何在 HTML 中显示表格主体?
在 HTML 中使用<tbody>标签来显示表格主体。HTML <tbody> 标签用于向表格添加主体。tbody 标签与 thead 标签和 tfoot 标签一起使用,以确定表格的每个部分(表头、表尾、主体)。以下是 <tbody> 标签的属性:
属性 |
值 |
描述 |
|---|---|---|
align |
右 左 居中 两端对齐 char |
已弃用 - 可视对齐。 |
char |
字符 |
已弃用 - 指定要对其文本的字符。当 align = "char" 时使用。 |
charoff |
像素或 % |
已弃用 - 指定相对于使用 char 属性指定的第一个字符的对齐偏移量(以像素或百分比值)。当 align = "char" 时使用。 |
valign |
顶部 中间 底部 基线 |
已弃用 - 垂直对齐。 |
示例
以下是显示 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