CSS3: caption-side プロパティ - 表の標題の表示位置

■ 概要

項  目説  明
記述形式 セレクタ {caption-side: }
値 の形式 topbottombeforeafter
初 期 値 before
対応ブラウザー C3+ / e8+ / N?+ / Fx1+ / Op4+ / Ch1+ / Sa1+
適用可能な要素 <table>
継  承 する

■ 解説

caption-sideプロパティ は,table要素 に対する指定で,caption要素(最初の子要素)による「標題」の表示位置 を指定します。

指定できる値の形式は,以下のとおりです。

説  明
top 標題は表(テーブル)の上に表示します。
bottom 標題は表(テーブル)の下に表示します。
before 標題は表(テーブル)の開始位置の前に表示します。 (初期値)
after 標題は表(テーブル)の終了位置の後に表示します。

CSS3 では,CSS2.1 までにあった topbottom に加えて,beforeafter の 2つの値が導入される予定です。 これは,縦書きの表などにも対応が可能なようにするためのようです。

通常の横書きの表では,beforeafter は,それぞれ, topbottom に同一になります。

■ 使用例( caption-side プロパティの利用)

HTMLソース
CSS
<head> ~ </head>
<style type="text/css" media="screen, handheld, print, tv" >
<!--
table.sample {
   border: 2px solid black;
   margin: 20px auto;
   border-collapse: collapse;
}
table.sample td {
   padding: 5px;
   border: 1px solid gray;
}
table.sample caption {
   font-weight: bold;
   margin: 5px;
}
caption.cp1 {
   caption-side: top;
}
caption.cp2 {
   caption-side: bottom;
}
-->
</style>
HTML
<body> ~ </body>
<table class="sample">
   <caption class="cp1">上位置キャプション</caption>
   <tr><td>テキスト1</td><td>テキスト2</td></tr>
   <tr><td>テキスト3</td><td>テキスト4</td></tr>
</table>
<table class="sample">
   <caption class="cp2">下位置キャプション</caption>
   <tr><td>テキスト1</td><td>テキスト2</td></tr>
   <tr><td>テキスト3</td><td>テキスト4</td></tr>
</table>

ブラウザー 表示例
上位置キャプション
テキスト1テキスト2
テキスト3テキスト4
下位置キャプション
テキスト1テキスト2
テキスト3テキスト4

■ 備考