HTML span 属性
定义和用法
span
属性定义一个 <col>
或 <colgroup>
元素应跨越的列数。
适用范围
span
属性可用于以下元素
元素 | Attribute |
---|---|
<col> | span |
<colgroup> | span |
示例
Col 示例
在这里,前两列应为红色背景
<table>
<colgroup>
<col span="2" style="background-color:red">
<col style="background-color:yellow">
</colgroup>
<tr>
<th>ISBN</th>
<th>标题</th>
<th>价格</th>
</tr>
<tr>
<td>3476896</td>
<td>我的第一个 HTML</td>
<td>$53</td>
</tr>
</table>
自己动手试一试 »
Colgroup 示例
使用 <colgroup> span 属性设置前两列的背景颜色
<table>
<colgroup span="2" style="background:red"></colgroup>
<tr>
<th>ISBN</th>
<th>标题</th>
<th>价格</th>
</tr>
<tr>
<td>3476896</td>
<td>我的第一个 HTML</td>
<td>$53</td>
</tr>
<tr>
<td>5869207</td>
<td>我的第一个 CSS</td>
<td>$49</td>
</tr>
</table>
自己动手试一试 »
浏览器支持
span
属性对每个元素的浏览器支持如下
元素 | |||||
---|---|---|---|---|---|
col | 是 | 是 | 是 | 是 | 是 |
colgroup | 是 | 是 | 是 | 是 | 是 |