搜索

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 创作

表格 <thead><tbody>

<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> 的默认样式:

详细样式教学可参考:CSS 教学、认识表格、表格默认样式

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;
}

意见反馈

微信二维码 微信扫码关注 抖音二维码 抖音扫码关注