col 标签为表格中一个或多个列定义属性值。
如需对全部列应用样式,col 标签很有用,这样就不需要对各个单元和各行重复应用样式了。
提示
如果您希望在 colgroup 内部为每个列规定不同的属性值时,请使用此元素。如果没有 col 元素,列会从 colgroup 那里继承所有的属性值。
col 元素是仅包含属性的空元素。如需创建列,您就必须在 tr 元素内部规定 td 元素。
使用 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:数字
规定 col 元素应跨越的列数。
大多数浏览器将使用以下默认值显示 col 元素:
col { display: table-column;}