HTML <colgroup> 標籤
實例
<colgroup> 和<col> 標籤為表格中的三個列設置了背景色:
<table border="1">
<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>My first HTML</td>
<td>$53</td>
</tr>
</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>My first HTML</td>
<td>$53</td>
</tr>
</table>
嘗試一下»
瀏覽器支持
所有主流瀏覽器都支持<colgroup> 標籤。
標籤定義及使用說明
<colgroup> 標籤用於對錶格中的列進行組合,以便對其進行格式化。
通過使用<colgroup> 標籤,可以向整個列應用樣式,而不需要重複為每個單元格或每一行設置樣式。
註釋:只能在<table>元素之內,在任何一個<caption>元素之後,在任何一個<thead>、<tbody>、<tfoot>、<tr>元素之前使用<colgroup>標籤。
提示:如果想對<colgroup>中的某列定義不同的屬性,請在<colgroup>標籤內使用<col>標籤。
HTML 4.01 與HTML5之間的差異
HTML5 中不再支持HTML 4.01 中的大部分屬性。
屬性
属性 | 值 | 描述 |
---|---|---|
align | left right center justify char |
HTML5 不支持。规定在列组合中内容的水平对齐方式。 |
char | character | HTML5 不支持。规定根据哪个字符来对齐列组中的内容。 |
charoff | number | HTML5 不支持。规定第一个对齐字符的偏移量。 |
span | number | 规定列组应该横跨的列数。 |
valign | top middle bottom baseline |
HTML5 不支持。定义在列组合中内容的垂直对齐方式。 |
width | pixels % relative_length |
HTML5 不支持。规定列组合的宽度。 |
全局屬性
<colgroup>標籤支持HTML的全局屬性 。
事件屬性
<colgroup>標籤支持HTML的事件屬性 。