表タイトルの位置を指定する

[新着] Webテンプレートを仮オープンしました


caption-side: ***;

ブラウザ
Netscape6 Firefox Opera
参考
書式基本 要素名 クラス ID

caption-side は、キャプション(表題)の表示位置を指定するプロパティです。

このスタイルはcaption要素に適用できます。


caption {
caption-side: bottom;
}


caption-side top … (表の上部に表示します)デフォルトNetscape6FirefoxOpera
bottom … (表の下部に表示します)Netscape6FirefoxOpera
left … (表の左に表示します)Netscape7Firefox
right … (表の右に表示します)Netscape7Firefox

text-align(left、center、right) や vertical-align(top、middle、bottom) プロパティと組み合わせると、より細かい位置指定が可能になります。

組み合わせ例

caption { caption-side: bottom; text-align: right; }
caption { caption-side: left; vertical-align: middle; }

メモ

left、またはrightを指定する場合は、キャプションが入る部分にマージンを指定しておくと綺麗に表示されます(下記の使用例でも指定しています)。この指定がないと、狭い範囲にキャプションを収めようとするので、縦長に表示されてしまいます。


使用例

<html>
<head>
<title>TAG index Webサイト</title>

<style type="text/css">
<!--

div { margin-bottom: 20px; }
table, td, th { border: 2px #2b2b2b solid; }


#example1 caption { caption-side: top; }

#example2 caption { caption-side: bottom; }

#example3 table { margin-left: 6em; }
#example3 caption { caption-side: left; }

#example4 table { margin-right: 6em; }
#example4 caption { caption-side: right; }


-->
</style>

</head>
<body>

<div id="example1">
<table>
<caption>topを指定</caption>
<tr>
<th>サーバー</th>
<th>Web制作</th>
</tr>
<tr>
<td>サーバーA社</td>
<td>Web制作A社</td>
</tr>
</table>
</div>

<div id="example2">
<table>
<caption>bottomを指定</caption>
<tr>
<th>サーバー</th>
<th>Web制作</th>
</tr>
<tr>
<td>サーバーA社</td>
<td>Web制作A社</td>
</tr>
</table>
</div>

<div id="example3">
<table>
<caption>leftを指定</caption>
<tr>
<th>サーバー</th>
<th>Web制作</th>
</tr>
<tr>
<td>サーバーA社</td>
<td>Web制作A社</td>
</tr>
</table>
</div>

<div id="example4">
<table>
<caption>rightを指定</caption>
<tr>
<th>サーバー</th>
<th>Web制作</th>
</tr>
<tr>
<td>サーバーA社</td>
<td>Web制作A社</td>
</tr>
</table>
</div>

</body>
</html>

これをブラウザで見ると次のように表示されます

topを指定
サーバー Web制作
サーバーA社 Web制作A社
bottomを指定
サーバー Web制作
サーバーA社 Web制作A社
leftを指定
サーバー Web制作
サーバーA社 Web制作A社
rightを指定
サーバー Web制作
サーバーA社 Web制作A社


[特集] レンタルサーバー比較 & サーバー選びのチェックポイント

サイト内検索について - ベーシック版