colgroup 标签用于规定表格中包含一列或多列的分组的格式。
如需对全部列应用样式,colgroup 标签很有用,这样就不需要对各个单元和各行重复应用样式了。
注意:colgroup 标签必须是 table 元素的子元素,位于任何 caption 元素之后和任何 thead、tbody、tfoot 和 tr 元素之前。
提示:如需为 colgroup 中的某一列定义不同的属性,请在 colgroup 标签中使用 col 标签。
使用 colgroup 和 col 标签设置三列的背景颜色:
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>书号</th>
<th>标题</th>
<th>价格</th>
</tr>
<tr>
<td>3476896</td>
<td>HTML 入门</td>
<td>$53</td>
</tr>
</table>span:数字
规定列组应跨越的列数。
大多数浏览器将使用以下默认值显示 colgroup 元素:
colgroup { display: table-column-group;}