HTML <col>タグ
例
<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>要素内の各列の<col>
列プロパティを指定します
。
この<col>
タグは、行ごとにセルごとにスタイルを繰り返すのではなく、列全体にスタイルを適用する場合に便利です。
ブラウザのサポート
Element | |||||
---|---|---|---|---|---|
<col> | Yes | Yes | Yes | Yes | Yes |
属性
Attribute | Value | Description |
---|---|---|
span | number | Specifies the number of columns a <col> element should span |
グローバル属性
この<col>
タグは、HTMLのグローバル属性もサポートしています。
イベント属性
この<col>
タグは、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:130px">Month</th>
<th
style="width:80px">Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</table>
関連ページ
HTML DOMリファレンス:列オブジェクト
デフォルトのCSS設定
ほとんどのブラウザは<col>
、次のデフォルト値で要素を表示します。
例
col {
display: table-column;
}