Flexbox 與 Grid
項目對齊方式justify-items
Controlling how items are aligned along its inline axis.
Overview
| Class | Declarations |
|---|---|
justify-items:normal | justify-items: normal;
|
justify-items:baseline | justify-items: baseline;
|
justify-items:left | justify-items: left;
|
justify-items:center | justify-items: center;
|
justify-items:right | justify-items: right;
|
justify-items:stretch | justify-items: stretch;
|
justify-items:legacy | justify-items: legacy;
|
justify-items:start | justify-items: start;
|
justify-items:end | justify-items: end;
|
justify-items:flex-start | justify-items: flex-start;
|
justify-items:flex-end | justify-items: flex-end;
|
justify-items:self-start | justify-items: self-start;
|
justify-items:self-end | justify-items: self-end;
|
justify-items:<value> | justify-items: <value>;
|
Examples
Align grid items inline
Use justify-items:* to set the default inline-axis alignment for children in a grid container.
<div class="grid justify-items:center"> ...</div>Generated CSS
@layer utilities { .grid { display: grid } .justify-items\:center { justify-items: center }}Stretch items by default
Use justify-items:stretch when grid children should fill their grid areas inline.
<section class="grid justify-items:stretch">...</section>Use justify-self when only one grid item needs different alignment.
Apply conditionally
Apply styles based on different states using selectors and conditional queries.
<div class="justify-items:stretch justify-items:center@sm justify-items:stretch@print">...</div>For flexbox main-axis distribution, use justify-content instead.