--- title: justify-items slug: Web/CSS/justify-items tags: - CSS - CSS Box Alignment - CSS Property - CSS プロパティ - CSS ボックス配置 - Reference - 'recipe:css-property' translation_of: Web/CSS/justify-items ---
CSS の justify-items プロパティは、ボックスのすべてのアイテムに既定の {{CSSxRef("justify-self")}} を定義し、それぞれのボックスの調整を適切な軸に沿って、既定の方法で行ないます。
このプロパティの効果は、現在のレイアウトモードに依存します。
/* 基本キーワード */ justify-items: auto; justify-items: normal; justify-items: stretch; /* 位置による配置 */ justify-items: center; /* 中央付近にアイテムを集める */ justify-items: start; /* 先頭側にアイテムを集める */ justify-items: end; /* 末尾側にアイテムを集める */ justify-items: flex-start; /* 'start' と同等です。なお、 justify-items はフレックスボックスレイアウト内では無視されます。 */ justify-items: flex-end; /* 'end' と同等です。なお、 justify-items はフレックスボックスレイアウト内では無視されます。 */ justify-items: self-start; justify-items: self-end; justify-items: left; /* 左側にアイテムを集める */ justify-items: right; /* 右側にアイテムを集める */ /* ベースラインの配置 */ justify-items: baseline; justify-items: first baseline; justify-items: last baseline; /* あふれたときの配置 (位置による配置時のみ) */ justify-items: safe center; justify-items: unsafe center; /* 従来の配置 */ justify-items: legacy right; justify-items: legacy left; justify-items: legacy center; /* グローバル値 */ justify-items: inherit; justify-items: initial; justify-items: unset;
このプロパティは4つの異なる形式のうち1つを取ることができます。
normal, auto, stretch のうちの一つ。baseline キーワードに加えて、任意で first または last のどちらか。center, start, end, flex-start, flex-end, self-start, self-end, left, right のうちの一つ。加えて任意で safe または unsafe。legacy キーワードに続いて、 left または right のどちらかの値。autojustify-items プロパティ、そうでなければ絶対位置であり、このような場合、 auto は normal を表します。normalstart の別名です。start のように動作し、その他の絶対位置ボックスには stretch のように動作します。stretch のうちの一つと似た動作をしますが、アスペクト比や固有の寸法を持つボックスは start のように振舞います。startendflex-startstart のように扱われます。flex-endend のように扱われます。self-startself-endcenterleftstart のように動作します。rightstart のように動作します。baseline
first baselinelast baselinefirst baseline の代替配置は start、 last baseline の代替配置は end です。stretchauto であるすべてのアイテムは (比例的にではなく) 均等に引き伸ばされます。ただし、 {{CSSxRef("max-height")}}/{{CSSxRef("max-width")}} (あるいは同等の機能) による制限は尊重します。これにより、寸法の合計が配置コンテナーを主軸に沿って完全に埋めるようになります。safestart であったかのように配置されます。unsafelegacyjustify-self: auto の値を持っている場合、 legacy キーワードは子孫からは考慮されず、関連付けられた left, right, center の値のみが継承されます。{{CSSInfo}}
次の例では、シンプルな 2 x 2 のグリッドレイアウトを示します。初期状態では、グリッドコンテナーには justify-items の値として stretch (既定値) が与えられており、グリッドアイテムはそのセルの幅全体に広がっています。
しかし、グリッドコンテナの上にマウスカーソルを置いたり、タブを押したりすると、グリッドアイテムには justify-items の値である center が与えられ、グリッドアイテムの幅はコンテンツの幅と同じだけ広がり、セルの中心に整列します。
<article class="container" tabindex="0"> <span>First child</span> <span>Second child</span> <span>Third child</span> <span>Fourth child</span> </article>
html {
font-family: helvetica, arial, sans-serif;
letter-spacing: 1px;
}
article {
background-color: red;
display: grid;
grid-template-columns: 1fr 1fr;
grid-auto-rows: 40px;
grid-gap: 10px;
width: 300px;
justify-items: stretch;
}
article:hover, article:focus {
justify-items: center;
}
article span {
background-color: black;
color: white;
margin: 1px;
text-align: center;
}
article, span {
padding: 10px;
border-radius: 7px;
}
article {
margin: 20px;
}
{{EmbedLiveSample('Simple_demonstration', '100%', 200)}}
| 仕様書 | 状態 | 備考 |
|---|---|---|
| {{SpecName("CSS3 Box Alignment", "#propdef-justify-items", "justify-items")}} | {{Spec2("CSS3 Box Alignment")}} | 初回定義 |
このページの互換性一覧表は構造化データから生成されています。データに協力していただけるのであれば、 https://github.com/mdn/browser-compat-data をチェックアウトしてプルリクエストを送信してください。
{{Compat("css.properties.justify-items.flex_context")}}
{{Compat("css.properties.justify-items.grid_context")}}