搜尋

表格元素 <thead><tbody><tfoot>

<thead><tbody><tfoot> 是 HTML 裡非必須的表格元素 ( 通常不會特別去使用 ),使用後能讓表格看起來更有架構性,這篇教學會介紹 <thead><tbody><tfoot> 的用法。

HTML 教學 - 表格 <thead>、<tbody>、<tfoot>

認識 <thead><tbody><tfoot>

<thead><tbody><tfoot> 是 HTML 裡非必須的表格元素,通常不會特別去使用,使用後能讓表格看起來更有架構性,<thead> 是表格的表頭,<tbody> 是表格的內容,<tfoot>則是表格的結尾。

  • <thead><tbody><tfoot> 屬於「容器元素」,需要有「起始標籤」以及「結束標籤」。
  • <thead> 顯示類型為「table-header-group」,只能作為 <table> 的子元素。
  • <tbody> 顯示類型為「table-row-group」,只能作為 <table> 的子元素。
  • <tfoot> 顯示類型為「table-footer-group」,只能作為 <table> 的子元素。

下方的 HTML 會在表格加入 <thead><tbody><tfoot> ( 額外加入邊界值樣式 )。

<style>
  td, th{
    padding:20px;
  }
</style>

<table border=1>
  <thead>
    <tr>
      <th></th>
      <th>a</th>
      <th>b</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>第一項</th>
      <td>10</td>
      <td>20</td>
    </tr>
    <tr>
      <th>第二項</th>
      <td>100</td>
      <td>200</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <th>加總</th>
      <td>110</td>
      <td>220</td>
    </tr>
  </tfoot>
</table>

HTML 教學 - 表格 <thead>、<tbody>、<tfoot>

<thead><tbody><tfoot> 支援屬性

<thead><tbody><tfoot> 支援「全域屬性」以及「可見元素的事件屬性」( 參考「HTML 元素屬性」),例如下方的 HTML,會將 <thead><tbody><tfoot> 加入 style 屬性,改變其背景顏色。

<style>
  td, th{
    padding:20px;
  }
</style>

<table border=1>
  <thead style="background:#ccc">
    <tr>
      <th></th>
      <th>a</th>
      <th>b</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>第一項</th>
      <td>10</td>
      <td>20</td>
    </tr>
    <tr>
      <th>第二項</th>
      <td>100</td>
      <td>200</td>
    </tr>
  </tbody>
  <tfoot style="background:#f99;">
    <tr>
      <th>加總</th>
      <td>110</td>
      <td>220</td>
    </tr>
  </tfoot>
</table>

HTML 教學 - 表格 <thead>、<tbody>、<tfoot>

<thead><tbody><tfoot> 預設樣式

下方是 <thead><tbody><tfoot> 的預設樣式:

thead {
  display: table-header-group;
  vertical-align: middle;
  border-color: inherit;
}

tbody {
  display: table-row-group;
  vertical-align: middle;
  border-color: inherit;
}

tfoot {
  display: table-footer-group;
  vertical-align: middle;
  border-color: inherit;
}

意見回饋

如果有任何建議或問題,可傳送「意見表單」給我,謝謝~

HTML 教學

基本介紹

認識 HTML 使用 HTML 編輯器

基礎知識

HTML 標籤與架構 HTML 格式規範 HTML 縮排與註解 HTML 元素顯示類型 HTML 元素屬性 HTML 特殊字元 HTML 色彩表示法 HTML 尺寸單位 HTML 網址與路徑 HTML 套用 CSS 樣式 HTML 套用 JavaScript 如何觀察 HTML 原始碼

網頁資訊元素

網頁標題 <title> 網頁資訊 <meta> 載入外部資源 <link> 重設根目錄 <base>

常用元素

標題 <h1>~<h6> 段落 <p> 行內容器 <span> 區塊容器 <div> 超連結 <a> 圖片 <img> 換行 <br> 水平分隔線 <hr> 內嵌頁框 <iframe>

文字樣式元素

粗體字 <strong><b> 斜體字 <em><i> 刪除線文字 <del> 插入 ( 底線 ) 文字 <ins> 小型文字 <small> 上標下標 <sup><sub> 凸顯文字 <mark> 引用 <blockquote><q> 預先格式化 <pre> 程式碼內容 <code> 收折文字內容 <details> 標示注音 <ruby><rt> 標示聯絡方式 <address> 標示鍵盤按鍵 <kbd> 標示時間日期 <time> 標示縮寫 <abbr> 標示可換行位置 <wbr>

表格&清單元素

無序清單 <ul><li> 有序清單 <ol><li> 自訂清單 <dl><dt><dd> 表格 <table><tr><td> 表格 <th><caption> 表格 <thead><tbody> 表格 <colgroup><col>

表單元素

表單 <form> 輸入 <input> 按鈕 <button> 多行文字輸入 <textarea> 下拉選單 <select> 進度條 <progress> 欄位標題 <label> 欄位資料清單 <datalist> 表單元素分組 <fieldset>

語意結構元素

頁首區塊 <header> 主要區塊 <main> 章節區塊 <section> 文章區塊 <article> 側邊欄區塊 <aside> 引用區塊 <figure> 導航連結區塊 <nav> 頁尾區塊 <footer>

影音&圖形元素

播放影片 <video> 播放聲音 <audio> 響應式圖片 <picture> 點陣畫布 <canvas> 向量圖形 <svg>

彈出視窗

alert() 警告視窗 confirm() 確認視窗 prompt() 輸入視窗

網頁嵌入應用

嵌入 YouTube 影片 嵌入 Google 地圖 嵌入 Google 日曆 嵌入 Google 表單 嵌入 Google 簡報 嵌入 Google 文件 嵌入 Google 試算表 嵌入 Google 試算表圖表 嵌入 Twitter 推文 嵌入 Facebook 粉絲團 嵌入 Facebook 影片 嵌入 Canva 簡報 嵌入 Scratch 創作