column-gap (grid-column-gap)

column-gapCSS のプロパティで、要素の段または列の間の隙間 () の寸法を設定します。

試してみましょう

当初は段組みレイアウトの一部でしたが、column-gap の定義は複数のレイアウト方式を含めるように拡張されました。現在はボックス配置の中で定義され、段組みレイアウト、フレキシブルボックス、グリッドレイアウトで使用されることがあります。

構文

css
/* キーワード値 */
column-gap: normal;

/* <length> 値 */
column-gap: 3px;
column-gap: 2.5em;

/* <percentage> 値 */
column-gap: 3%;

/* グローバル値 */
column-gap: inherit;
column-gap: initial;
column-gap: revert;
column-gap: unset;

column-gap プロパティは以下に挙げた値の一つで指定します。

normal

列間 (段間) にはブラウザー既定の幅が使われます。段組みレイアウトでは 1em と指定され、他の種類のレイアウトでは 0 になります。

<length>

列間 (段間) の寸法を <length> として定義します。 <length> のプロパティ値は負の数であってはいけません。

<percentage>

列間 (段間) の寸法を <percentage> として定義します。 <percentage> のプロパティ値は負の数であってはいけません。

公式定義

初期値normal
適用対象段組み要素、フレックスコンテナー、グリッドコンテナー
継承なし
パーセント値コンテンツ領域の対応する寸法に対する相対値
計算値指定通りで、 <length> は絶対長になり、 normal の計算値は段組み要素を除き 0 になる
アニメーションの種類length または パーセント値, calc();

形式文法

column-gap = 
normal |
<length-percentage [0,∞]>

<length-percentage> =
<length> |
<percentage>

フレックスレイアウト

HTML

html
<div id="flexbox">
  <div></div>
  <div></div>
  <div></div>
</div>

CSS

css
#flexbox {
  display: flex;
  height: 100px;
  column-gap: 20px;
}

#flexbox > div {
  border: 1px solid green;
  background-color: lime;
  flex: auto;
}

結果

グリッドレイアウト

HTML

html
<div id="grid">
  <div></div>
  <div></div>
  <div></div>
</div>

CSS

css
#grid {
  display: grid;
  height: 100px;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: 100px;
  column-gap: 20px;
}

#grid > div {
  border: 1px solid green;
  background-color: lime;
}

結果

段組みレイアウト

HTML

html
<p class="content-box">
  This is some multi-column text with a 40px column gap created with the CSS
  `column-gap` property. Don't you think that's fun and exciting? I sure do!
</p>

CSS

css
.content-box {
  column-count: 3;
  column-gap: 40px;
}

結果

仕様書

Specification
CSS Box Alignment Module Level 3
# column-row-gap
CSS Grid Layout Module Level 2
# gutters
CSS Multi-column Layout Module Level 1
# column-gap

ブラウザーの互換性

BCD tables only load in the browser

関連情報