HTML <colgroup>タグ
例
<colgroup>タグと<col>タグを使用して3つの列の背景色を設定します。
<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>
タグは、フォーマット用のテーブル内の1つ以上の列のグループを指定します。
この<colgroup>
タグは、行ごとにセルごとにスタイルを繰り返すのではなく、列全体にスタイルを適用する場合に便利です。
注:タグは、<table>要素の<colgroup>
子であり、<caption>要素の後、<thead>、<tbody>、<tfoot>、および<tr>要素の前にある必要があります。
ヒント:内の列にさまざまなプロパティを定義するには、タグ内で<col><colgroup>
タグを使用します。<colgroup>
ブラウザのサポート
Element | |||||
---|---|---|---|---|---|
<colgroup> | Yes | Yes | Yes | Yes | Yes |
属性
Attribute | Value | Description |
---|---|---|
span | number | Specifies the number of columns a column group should span |
グローバル属性
この<colgroup>
タグは、HTMLのグローバル属性もサポートしています。
イベント属性
この<colgroup>
タグは、HTMLのイベント属性もサポートしています。
その他の例
例
表の列にテキストを揃える(CSSを使用):
<table style="width:100%">
<tr>
<th>ISBN</th>
<th>Title</th>
<th>Price</th>
</tr>
<tr>
<td>3476896</td>
<td>My first HTML</td>
<td style="text-align:right">$53</td>
</tr>
<tr>
<td>2489604</td>
<td>My first CSS</td>
<td style="text-align:right">$47</td>
</tr>
</table>
例
テーブル列のテキストを垂直方向に揃えます(CSSを使用):
<table style="height:200px">
<tr>
<th>Month</th>
<th
style="vertical-align:bottom">Savings</th>
</tr>
<tr>
<td>January</td>
<td
style="vertical-align:bottom">$100</td>
</tr>
</table>
例
テーブル列の幅を指定します(CSSを使用)。
<table>
<tr>
<th
style="width:200px">Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
関連ページ
HTML DOMリファレンス:ColumnGroupオブジェクト
デフォルトのCSS設定
ほとんどのブラウザは<colgroup>
、次のデフォルト値で要素を表示します。
例
colgroup {
display: table-column-group;
}