align-items
Specifies how items are aligned along the cross axis of a flex container. For 'flex-direction: row', this controls vertical alignment; for 'column', it controls horizontal alignment.
Sample Code
/* Stretch to fill the container height (default) */
.container { display: flex; align-items: stretch;}
/* Align to top */
.container-start { display: flex; align-items: flex-start;}
/* Center alignment */
.container-center { display: flex; align-items: center;}
/* Align to bottom */
.container-end { display: flex; align-items: flex-end;}
/* Align to text baseline */
.container-base { display: flex; align-items: baseline;}
Available Values
| Value | Description |
|---|---|
| stretch | アイテムをコンテナの交差軸方向いっぱいに伸ばします。初期Valueです。 |
| flex-start | Aligns items to the start of the cross axis. |
| flex-end | Aligns items to the end of the cross axis. |
| center | Centers items along the cross axis. |
| baseline | Aligns items to the text baseline (the bottom edge of characters) within the items. |
Specification
| Property | Details |
|---|---|
| 初期Value | stretch |
| Applies to | Flex containers (elements with 'display: flex' or 'display: inline-flex') |
| Inherited | No |
| Animation | Not animatable (discrete) |
Browser Support
28 △
27 △
26 △
25 △
24 △
23 △
22 △
21 △
20 and earlier ×
19 and earlier ×
7 △
6 and earlier ×
8 ×
7 ×
6 ×
14 and earlier ×
7 △
6 and earlier ×
Android Browser
4.4 + ○
3 and earlier ×Description
The 'align-items' property is specified on a flex container to control item alignment along the cross axis (vertical when 'flex-direction: row'). The 'justify-content' property handles the main axis, while 'align-items' handles the cross axis.
各Valueの配置イメージ
stretch(初期Value)
アイテムにサイズ(『height』や『width』)が明示的に指定されていない場合、コンテナの交差軸方向いっぱいに引き伸ばされます。これが初期Valueであるため、『display: flex』を指定しただけでアイテムのHeights equalizedのはこのPropertyの効果です。アイテムに明示的なサイズが指定されている場合は『stretch』でも伸ばされません。
center
Centers items along the cross axis.『justify-content: center』と組み合わせることで、上下左右の完全な中央配置が実現できます。これはFlexboxの最も代表的な使い方の一つです。
/* Perfect centering in all directions */
.perfect-center {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
baseline
各アイテム内のテキストのBaseline(文字の底辺の線)を揃えます。フォントサイズが異なるアイテムが混在する場合に、テキストの位置を自然に揃えたいときに使います。
/* Align text positions of elements with different font sizes */
.nav {
display: flex;
align-items: baseline;
}
.nav-title { font-size: 24px;}
.nav-link { font-size: 14px;}
Changing Alignment for Individual Items
To change the cross-axis alignment for a specific item only, use the 'align-self' property on that item. The 'align-items' property is a bulk setting for the entire container, while 'align-self' is for individual items.
.container {
display: flex;
align-items: flex-start; /* All items align to top */
}
.special-item {
align-self: flex-end; /* Only this item aligns to bottom */
}
Related Properties
| Property | Description |
|---|---|
| justify-content | Controls item alignment along the main axis. Can be combined with 'align-items' to control alignment in all directions. |
| align-self | Specifies the cross-axis alignment for individual items. Overrides 'align-items'. |
| align-content | Controls row spacing when there are multiple lines. 'align-items' handles item alignment within a row, while 'align-content' handles the positioning of all rows. |
| flex-direction | 主軸の方向を指定します。『align-items』が効く方向はこのPropertyのValueによって変わります。 |
If you find any errors or copyright issues, please contact us.