📅  最后修改于: 2023-12-03 15:15:44.250000             🧑  作者: Mango
<col>
标签用于定义表格中的列属性,可以通过该标签设置列宽、对齐方式、颜色、背景色等属性。
<col attribute="value">
其中,attribute
为列属性,value
为属性的值。
以下是 col
标签的常用属性:
align
:设置列的对齐方式,可选值为 left
、right
、center
、justify
、char
。bgcolor
:设置列的背景色。span
:设置列的跨度,可以跨越多个列。width
:设置列的宽度。除此之外,col
标签还可以使用 CSS 样式进行定义。
下面是一个 col
标签的使用示例:
<table>
<colgroup>
<col style="background-color: #eee;">
<col style="background-color: #f2f2f2;">
</colgroup>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Doe</td>
</tr>
</tbody>
</table>
在上述示例中,我们使用了 colgroup
元素来将两列属性包含在一起,并分别指定了它们的背景颜色。这样,我们就可以在不改变表格内容的情况下,仅通过设置列属性来美化表格。
<col>
标签必须在 <colgroup>
中使用,否则无法生效。<col>
中设置的属性是全局的,所有使用该列的单元格都会继承这些属性。