caption-side

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

caption-sideCSS のプロパティで、表 (<table>) の <caption> の中身を指定された側に配置します。この値は表の writing-mode に対する相対値です。

試してみましょう

caption-side: top;
caption-side: bottom;
<section class="default-example" id="default-example">
  <table class="transition-all" id="example-element">
    <caption>
      有名な動物
    </caption>
    <tr>
      <th>名前</th>
      <th>場所</th>
    </tr>
    <tr>
      <td>キリン</td>
      <td>アフリカ</td>
    </tr>
    <tr>
      <td>ペンギン</td>
      <td>南極</td>
    </tr>
    <tr>
      <td>ナマケモノ</td>
      <td>南アメリカ</td>
    </tr>
    <tr>
      <td>トラ</td>
      <td>アジア</td>
    </tr>
  </table>
</section>
table {
  font-size: 1.2rem;
  text-align: left;
  color: #000;
}

th,
td {
  padding: 0.2rem 1rem;
}

caption {
  background: #fc3;
  padding: 0.5rem 1rem;
}

tr {
  background: #eee;
}

tr:nth-child(even) {
  background: #ccc;
}

構文

css
/* 方向を示す値 */
caption-side: top;
caption-side: bottom;

/* グローバル値 */
caption-side: inherit;
caption-side: initial;
caption-side: revert;
caption-side: revert-layer;
caption-side: unset;

caption-side プロパティは、以下のキーワード値のうちの一つで指定します。

top

キャプションボックスを表のブロック方向の先頭に配置します。

bottom

キャプションボックスを表のブロック方向の末尾に配置します。

メモ: CSS の論理的プロパティと値モジュールでは、キャプションボックスをテーブルのインライン先頭側の端およびインライン末尾側の端にそれぞれ配置するための 2 つの論理値、 inline-start および inline-end を定義しています。これらの値は、どのブラウザーでも対応していません。

公式定義

初期値top
適用対象表のキャプション要素
継承あり
計算値指定通り
アニメーションの種類離散値

形式文法

caption-side = 
top |
bottom

キャプションを上や下に設定

HTML

html
<table class="top">
  <caption>
    この表の上側のキャプション
  </caption>
  <tr>
    <td>いくつかのデータ</td>
    <td>もっと多くのデータ</td>
  </tr>
</table>

<br />

<table class="bottom">
  <caption>
    この表の下側のキャプション
  </caption>
  <tr>
    <td>いくつかのデータ</td>
    <td>もっと多くのデータ</td>
  </tr>
</table>

CSS

css
.top caption {
  caption-side: top;
}

.bottom caption {
  caption-side: bottom;
}

table {
  border: 1px solid red;
}

td {
  border: 1px solid blue;
}

結果

仕様書

Specification
Cascading Style Sheets Level 2
# propdef-caption-side
CSS Logical Properties and Values Level 1
# caption-side

ブラウザーの互換性

関連情報