如何在 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>

更新日期: 10-Oct-2023

777 瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始
廣告