HTML <colgroup> 标签用于指定 HTML 表格中的一组列。它作为一个父容器包含一个或多个 <col> 元素,以应用不同的属性到 HTML 表格中的列。

注意:<colgroup> 标签必须在 <table> 元素中的 <caption> 元素之后、<thead><tbody> 元素之前使用。

语法

  1. <colgroup>......</colgroup>

以下是 HTML <colgroup> 标签的一些规定:

显示方式
开始标签/结束标签开始标签和结束标签
用途HTML 表格

示例

<!DOCTYPE html>
<html>
<head>
  <title>Colgroup 标签</title>
</head>
<body>
  <h2>Colgroup 标签示例</h2>
  <table border="1">
    <colgroup>
      <col style="background-color: green" width="40">
      <col span="2" style="background-color: #ff7256" width="80">
    </colgroup>
    <tr>
      <th>Sr.No</th>
      <th>Product</th>
      <th>Price</th>
    </tr>
    <tr>
      <td>1</td>
      <td>Rice</td>
      <td>85</td>
    </tr>
    <tr>
      <td>2</td>
      <td>Butter</td>
      <td>260</td>
    </tr>
    <tr>
      <td>3</td>
      <td>Mango</td>
      <td>125</td>
    </tr>
  </table>
</body>
</html>

属性

属性描述
alignleftcenterrightjustifychar它指定列内容的对齐方式(在 HTML5 中不受支持)。
charcharacter它指定列组中内容相对于字符的对齐方式(在 HTML5 中不受支持)。
charoffnumber它设置从 char 属性指定的对齐字符偏移列数据的字符数(在 HTML5 中不受支持)。
spannumber它指定 colgroup 应跨越的列数。
valigntopmiddlebottombaseline它指定列组的垂直对齐方式(在 HTML5 中不受支持)。
width%Pixelsrelative_length它指定列组的宽度(在 HTML5 中不受支持)。

全局属性

HTML <colgroup> 标签支持 HTML 中的所有全局属性。

事件属性

HTML <colgroup> 标签支持 HTML 中的所有事件属性。

支持的浏览器

元素chrome 浏览器 Chromeie 浏览器 IEfirefox 浏览器 Firefoxopera 浏览器 Operasafari 浏览器 Safari
<colgroup>

标签: html, HTML教程, HTML技术, HTML学习, HTML学习教程, HTML下载, HTML语言, HTML开发, HTML入门教程, HTML进阶教程, HTML高级教程, HTML面试题, HTML笔试题, HTML编程思想