在 HTML 中如何建立表格標題?


在 HTML 中使用 <thead> 標籤來建立表格標題。HTML <thead> 標籤用於給表格新增標題。thead 標籤與 tbody 標籤和 tfoot 標籤結合使用來定義表格的各個部分(標題、頁尾、正文)。

HTML <thead> 標籤還支援以下附加屬性 −

屬性

說明
align
right
left
center
justify
char
已棄用 − 視覺對齊。
char
character
已棄用 − 指定將文字對齊到哪個字元。在 align = "char" 時使用
charoff
畫素或百分比
已棄用 − 指定與使用 char 屬性指定的第一個字元相比的對齊偏移(以畫素或百分比為單位)。在 align = "char" 時使用
valign
top
middle
bottom
baseline
已棄用 − 垂直對齊。

示例

你可以嘗試執行以下程式碼來學習如何在 HTML 中實現 <thead> 標籤 −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML thead 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>
            ...more rows here containing four cells...
            </tr>
         </tbody>
     
         <tbody>
            <tr>
               <td>Cell 1</td>
               <td>Cell 2</td>
               <td>Cell 3</td>
               <td>Cell 4</td>
            </tr>
            <tr>
            ...more rows here containing four cells...
            </tr>
         </tbody>
      </table>
   </body>
</html>

更新於:2020 年 5 月 27 日

492 次瀏覽

開啟你的 職業 生涯

完成課程即可獲得認證

開始
廣告