Tag <col> HTML
- Previous Page <code>
- Next Page <colgroup>
定义和用法
<col>
标签为表格中一个或多个列定义属性值。
如需对全部列应用样式,<col>
标签很有用,这样就不需要对各个单元和各行重复应用样式了。
提示
如果您希望在 colgroup 内部为每个列规定不同的属性值时,请使用此元素。如果没有 col 元素,列会从 colgroup 那里继承所有的属性值。
col 元素是仅包含属性的空元素。如需创建列,您就必须在 tr 元素内部规定 td 元素。
另请参阅:
HTML 参考手册:<colgroup> 标签
HTML DOM 参考手册:Column 对象
实例
使用 <colgroup> 和 <col> 标签设置三列的背景颜色:
<table> <colgroup> <col span="2" style="background-color:red"> <col style="background-color:yellow"> </colgroup> <tr> <th>ISBN</th> <th>Title</th> <th>Price</th> </tr> <tr> <td>3476896</td> <td>HTML Entry</td> <td>$53</td> </tr> </table>
Attribute
Attribute | Value | Description |
---|---|---|
span | Number | Specifies the number of columns that the <col> element should span. |
Global Attributes
<col>
The tag also supports Global Attributes in HTML.
Event Attributes
<col>
The tag also supports Event Attributes in HTML.
Default CSS Settings
Most browsers will display the following default values <col>
Element:
col { display: table-column; }
Browser Support
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support |
- Previous Page <code>
- Next Page <colgroup>