--- title: justify-content slug: Web/CSS/justify-content tags: - CSS - CSS プロパティ - CSS ボックス配置 - Reference - justify-content - place-content translation_of: Web/CSS/justify-content ---
CSS の justify-content プロパティは、フレックスコンテナーの{{Glossary("Main Axis", "主軸")}}およびグリッドコンテナーのインライン軸に沿って、中身のアイテムの間や周囲に間隔を配置する方法を定義します。
このデモはグリッドレイアウトを用いていくつかの値を紹介します。
このデモのソースファイルは GitHub リポジトリに格納されています。デモプロジェクトに協力したい場合は、 https://github.com/mdn/interactive-examples をクローンしてプルリクエストを送信してください。
長さや自動マージンが適用された後に配置が行われることから、フレックスボックスレイアウトで {{cssxref("flex-grow")}} が 0 ではないフレックス要素が少なくとも 1 つある場合は利用可能なスペースがなくなりますので、このプロパティの効果はないでしょう。
/* 位置による配置 */
justify-content: center; /* アイテムを中央に寄せる */
justify-content: start; /* アイテムを先頭に寄せる */
justify-content: end; /* アイテムを末尾に寄せる */
justify-content: flex-start; /* フレックスアイテムを先頭に寄せる */
justify-content: flex-end; /* フレックスアイテムを末尾に寄せる */
justify-content: left; /* アイテムを左端に寄せる */
justify-content: right; /* アイテムを右端に寄せる */
/* ベースラインによる配置 */
/* justify-content はベースラインの値を取りません */
/* 通常の配置 */
justify-content: normal;
/* 均等配置 */
justify-content: space-between; /* 各アイテムを均等に配置し
最初のアイテムは先頭に寄せ、
最後のアイテムは末尾に寄せる */
justify-content: space-around; /* 各アイテムを均等に配置し
各アイテムの両側に半分の大きさの
間隔を置く */
justify-content: space-evenly; /* 各アイテムを均等に配置し
各アイテムの周りに同じ大きさの間隔を置く */
justify-content: stretch; /* 各アイテムを均等に配置し
サイズが 'auto' であるアイテムは、
コンテナーに合わせて引き伸ばす */
/* あふれた場合の配置 */
justify-content: safe center;
justify-content: unsafe center;
/* グローバル値 */
justify-content: inherit;
justify-content: initial;
justify-content: unset;
startendflex-startstart のように扱われます。flex-endend のように扱われます。centerleftstart のように動作します。rightstart のように動作します。normaljustify-content の値が設定されていないかのように、既定の位置に寄せて配置されます。この値はグリッドおよびフレックスコンテナーの stretch として動作します。baseline
first baselinelast baselinefirst baseline の代替配置は start、last baseline の代替配置は end です。space-betweenspace-aroundspace-evenlystretch各アイテムの主軸に沿った寸法の合計が配置コンテナーの寸法よりも小さい場合、寸法が auto のアイテムは、 {{cssxref("max-height")}}/{{cssxref("max-width")}} (または同等の機能) での制約を尊重しつつ、 (比例的にではなく) 均等に引き伸ばされ、主軸方向の寸法の合計が配置コンテナーを満たすようになります。
メモ: stretch はフレキシブルボックス (フレックスボックス) は対応していません。
safestart であったかのように配置されます。unsafe#container {
display: flex;
justify-content: space-between; /* live sample で変更可能 */
}
#container > div {
width: 100px;
height: 100px;
background: linear-gradient(-45deg, #788cff, #b4c8ff);
}
<div id="container"> <div></div> <div></div> <div></div> </div> <select id="justifyContent"> <option value="start">start</option> <option value="end">end</option> <option value="flex-start">flex-start</option> <option value="flex-end">flex-end</option> <option value="center">center</option> <option value="left">left</option> <option value="right">right</option> <option value="baseline">baseline</option> <option value="first baseline">first baseline</option> <option value="last baseline">last baseline</option> <option value="space-between" selected>space-between</option> <option value="space-around">space-around</option> <option value="space-evenly">space-evenly</option> <option value="stretch">stretch</option> </select>
var justifyContent = document.getElementById("justifyContent");
justifyContent.addEventListener("change", function (evt) {
document.getElementById("container").style.justifyContent =
evt.target.value;
});
{{EmbedLiveSample("Example", "100%", 140)}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName('CSS3 Box Alignment', '#propdef-justify-content', 'justify-content')}} | {{Spec2('CSS3 Box Alignment')}} | [ first | last ]? baseline, self-start, self-end, start, end, left, right, unsafe | safe の値を追加 |
| {{SpecName('CSS3 Flexbox', '#propdef-justify-content', 'justify-content')}} | {{Spec2('CSS3 Flexbox')}} | 初回定義 |
{{Compat("css.properties.justify-content.flex_context")}}
{{Compat("css.properties.justify-content.grid_context")}}