column-gap (grid-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>のプロパティ値は負の数であってはいけません。
公式定義
関連情報
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
関連情報
- 関連する CSS プロパティ:
row-gap,gap - グリッドレイアウトのガイド: グリッドレイアウトの基本概念 - 溝
- 段組みレイアウトのガイド: 段組みのスタイル付け