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


使用 <colgroup> 标签来包含表格列组。HTML <colgroup> 标签用于指定表格内一组列的属性。如果需要为列组内的列应用不同的属性,可以在 <colgroup> 标签内使用 HTML <col> 标签。

以下是属性:

属性

描述
Align
right
left
center
justify
char
定义水平对齐方式,HTML5 中不支持
Char
字符
定义用于对齐文本的字符(与 align ="char" 一起使用),HTML5 中不支持
Charoff
像素
定义 <col> 应跨越的列数,HTML5 中不支持
Span
数字
定义 <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.