align-self
Specifies the cross-axis alignment for individual flex items. Can override the container's 'align-items' value.
Sample Code
/* Follow the container's align-items (default) */
.item { align-self: auto;}
/* Center this item only */
.item-center { align-self: center;}
/* Align this item to the bottom only */
.item-end { align-self: flex-end;}
/* Stretch this item only */
.item-stretch { align-self: stretch;}
Available Values
| Value | Description |
|---|---|
| auto | コンテナの『align-items』のValueを使います。初期Valueです。 |
| flex-start | Aligns the item to the start of the cross axis. |
| flex-end | Aligns the item to the end of the cross axis. |
| center | Centers the item along the cross axis. |
| baseline | Aligns the item to the text baseline within the item. |
| stretch | Stretches the item to fill the cross axis. |
Specification
| Property | Details |
|---|---|
| 初期Value | auto |
| Applies to | Flex items |
| Inherited | No |
| Animation | Not animatable (discrete) |
Browser Support
Desktop
28 △
27 △
26 △
25 △
24 △
23 △
22 △
21 △↑ Requires prefix '-webkit-'
20 and earlier ×
19 and earlier ×
7 △↑ Requires prefix '-webkit-'
6 and earlier ×Supported in all versions.
8 ×
7 ×
6 ×
11 and earlier ×Mobile
7 △↑ Requires prefix '-webkit-'
6 and earlier ×
Android Browser
4.4 + ○
3 and earlier ×Same support as desktop version
Same support as desktop version
Description
『align-self』はFlex itemsに指定するPropertyで、コンテナに設定された『align-items』のValueをそのアイテムだけ上書きできます。「全体は上揃えだけど、このアイテムだけ中央に配置したい」といった場合に使います。
Relationship with align-items
『align-items』はコンテナに指定して全アイテムの揃え方を一括で決めるPropertyです。『align-self』はアイテムに指定して個別に上書きするPropertyです。『align-self: auto』(初期Value)の場合は、コンテナの『align-items』のValueがそのまま適用されます。
.container {
display: flex;
align-items: flex-start; /* All items align to top */
height: 200px;
}
.item-a { /* align-self: auto -> flex-start is applied */ }
.item-b { align-self: center;} /* Only this item is centered */
.item-c { align-self: flex-end;} /* Only this item aligns to bottom */
Pattern: Pin Footer to Bottom
/* Pin only the footer to the bottom within a card */
.card {
display: flex;
flex-direction: column;
height: 300px;
}
.card-body { flex: 1;}
.card-footer {
align-self: flex-end; /* Place at the end of the cross axis (horizontal) */
}
Related Properties
| Property | Description |
|---|---|
| align-items | コンテナ内の全アイテムの交差軸方向の揃え方を一括で指定します。『align-self』はこのValueを個別に上書きします。 |
| justify-content | 主軸方向の配置を制御します。個々のアイテムの主軸方向の配置を個別に変更するPropertyは標準にはありません(『margin: auto;』で代用可能)。 |
If you find any errors or copyright issues, please contact us.