HTML教程-HTML<colgroup>标签
HTML <colgroup> 标签用于指定 HTML 表格中的一组列。它作为一个父容器包含一个或多个 <col> 元素,以应用不同的属性到 HTML 表格中的列。
注意:<colgroup> 标签必须在 <table> 元素中的 <caption> 元素之后、<thead> 或 <tbody> 元素之前使用。
语法
<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>属性
| 属性 | 值 | 描述 |
|---|---|---|
| align | leftcenterrightjustifychar | 它指定列内容的对齐方式(在 HTML5 中不受支持)。 |
| char | character | 它指定列组中内容相对于字符的对齐方式(在 HTML5 中不受支持)。 |
| charoff | number | 它设置从 char 属性指定的对齐字符偏移列数据的字符数(在 HTML5 中不受支持)。 |
| span | number | 它指定 colgroup 应跨越的列数。 |
| valign | topmiddlebottombaseline | 它指定列组的垂直对齐方式(在 HTML5 中不受支持)。 |
| width | %Pixelsrelative_length | 它指定列组的宽度(在 HTML5 中不受支持)。 |
全局属性
HTML <colgroup> 标签支持 HTML 中的所有全局属性。
事件属性
HTML <colgroup> 标签支持 HTML 中的所有事件属性。
支持的浏览器
| 元素 | Chrome | IE | Firefox | Opera | Safari |
|---|---|---|---|---|---|
<colgroup> | 是 | 是 | 是 | 是 | 是 |
Chrome
IE
Firefox
Opera
Safari