如何在 HTML 中包含表格列組?


使用 <colgroup> 標籤來包含表格列組。HTML <colgroup> 標籤用於指定表格中列組的屬性。如果您需要為列組中的列應用不同的屬性,可以在 colgroup 標籤內使用 HTML col 標籤。

以下是屬性:

屬性

描述
Align
right
left
center
justify
char
定義水平對齊方式,HTML5 中不支援
Char
character
定義用於文字對齊的字元(與 align ="char" 一起使用),HTML5 中不支援
Charoff
pixel
定義 <col> 應跨越的列數,HTML5 中不支援
Span
number
定義 <col> 應跨越的列數,HTML5 中不支援
Valign
bottom
middle
top
baseline
定義垂直對齊方式,HTML5 中不支援
Width
畫素或 %
指定當前 col 元素跨越的每一列的預設寬度,HTML5 中不支援

示例

您可以嘗試執行以下程式碼以在 HTML 中實現 <colgroup> 標籤:

<!DOCTYPE html>
<html>
   <head>
      <title>HTML col Tag</title>
   </head>
   <body>
      <p>This example shows a colgroup that has three columns of different widths:</p>
      <table border = "1">
         <colgroup span = "4">
            <col width = "40"></col>
            <col width = "70"></col>
            <col width = "100"></col>
            <col width = "130"></col>
            <col width = "160"></col>
            </colgroup>
         <tr>
            <td>One</td>
            <td>Two</td>
            <td>Three</td>
            <td>Four</td>
            <td>Five</td>
         </tr>
      </table>
   </body>
</html>

更新於:2020年5月30日

1K+ 次瀏覽

啟動您的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.