align-self
CSS
property overrides a grid or flex item's
align-items
value. In Grid, it aligns the item inside the
grid area
. In Flexbox, it aligns the item on the
cross axis
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The property doesn't apply to block-level boxes, or to table cells. If a flexbox item's cross-axis margin is
auto
, then
align-self
被忽略。
/* Keyword values */ align-self: auto; align-self: normal; /* Positional alignment */ /* align-self does not take left and right values */ align-self: center; /* Put the item around the center */ align-self: start; /* Put the item at the start */ align-self: end; /* Put the item at the end */ align-self: self-start; /* Align the item flush at the start */ align-self: self-end; /* Align the item flush at the end */ align-self: flex-start; /* Put the flex item at the start */ align-self: flex-end; /* Put the flex item at the end */ /* Baseline alignment */ align-self: baseline; align-self: first baseline; align-self: last baseline; align-self: stretch; /* Stretch 'auto'-sized items to fit the container */ /* Overflow alignment */ align-self: safe center; align-self: unsafe center; /* Global values */ align-self: inherit; align-self: initial; align-self: unset;
auto
align-items
值。
normal
start
on
replaced
absolutely-positioned boxes, and as
stretch
on
all other
absolutely-positioned boxes.
stretch
.
stretch
.
stretch
, except for boxes with an aspect ratio or an intrinsic sizes where it behaves like
start
.
self-start
Aligns the items to be flush with the edge of the alignment container corresponding to the item's start side in the cross axis.
self-end
Aligns the items to be flush with the edge of the alignment container corresponding to the item's end side in the cross axis.
flex-start
The cross-start margin edge of the flex item is flushed with the cross-start edge of the line.
flex-end
The cross-end margin edge of the flex item is flushed with the cross-end edge of the line.
center
The flex item's margin box is centered within the line on the cross-axis. If the cross-size of the item is larger than the flex container, it will overflow equally in both directions.
baseline
first baseline
last baseline
first baseline
is
start
, the one for
last baseline
is
end
.
stretch
auto
-sized, its size is increased equally (not proportionally), while still respecting the constraints imposed by
max-height
/
max-width
(or equivalent functionality), so that the combined size of all
auto
-sized items exactly fills the alignment container along the cross axis.
safe
start
.
unsafe
Regardless of the relative sizes of the item and alignment container, the given alignment value is honored.
| 初始值 |
auto
|
|---|---|
| 适用于 | flex items, grid items, and absolutely-positioned boxes |
| 继承 | no |
| 计算值 |
auto
computes to itself on absolutely-positioned elements, and to the computed value of
align-items
on the parent (minus any legacy keywords) on all other boxes, or
start
if the box has no parent. Its behavior depends on the layout model, as described for
justify-self
. Otherwise the specified value.
|
| 动画类型 | discrete |
auto | normal | stretch | <baseline-position> | <overflow-position>? <self-position>where
<baseline-position> = [ first | last ]? baseline
<overflow-position> = unsafe | safe
<self-position> = center | start | end | self-start | self-end | flex-start | flex-end
<section> <div>Item #1</div> <div>Item #2</div> <div>Item #3</div> </section>
section {
display: flex;
align-items: center;
height: 120px;
background: beige;
}
div {
height: 60px;
background: cyan;
margin: 5px;
}
div:nth-child(3) {
align-self: flex-end;
background: pink;
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
CSS Box Alignment Module Level 3
The definition of 'align-self' in that specification. |
工作草案 | Update to latest syntax definitions. |
|
CSS Flexible Box Layout Module
The definition of 'align-self' in that specification. |
候选推荐 | 初始定义。 |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Supported in Flex Layout |
Chrome
完整支持
36
|
Edge 完整支持 12 |
Firefox
完整支持
20
注意事项
|
IE 完整支持 11 | Opera 完整支持 12.1 | Safari 完整支持 9 |
WebView Android
完整支持
37
|
Chrome Android
完整支持
36
|
Firefox Android
完整支持
20
注意事项
|
Opera Android 完整支持 12.1 | Safari iOS 完整支持 9 |
Samsung Internet Android
完整支持
3.0
|
baseline
|
Chrome 完整支持 57 | Edge 完整支持 79 | Firefox 完整支持 45 | IE 不支持 No | Opera 完整支持 44 | Safari 不支持 No | WebView Android 完整支持 57 | Chrome Android 完整支持 57 | Firefox Android 完整支持 45 | Opera Android 完整支持 43 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 7.0 |
first baseline
and
last baseline
|
Chrome 完整支持 57 | Edge 完整支持 79 | Firefox 完整支持 52 | IE 不支持 No | Opera 完整支持 44 | Safari 不支持 No | WebView Android 完整支持 57 | Chrome Android 完整支持 57 | Firefox Android 完整支持 52 | Opera Android 完整支持 43 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 7.0 |
left
and
right
|
Chrome 不支持 No | Edge 不支持 No | Firefox 完整支持 52 | IE 不支持 No | Opera 不支持 No | Safari 不支持 No | WebView Android 不支持 No | Chrome Android 不支持 No | Firefox Android 完整支持 52 | Opera Android 不支持 No | Safari iOS 不支持 No | Samsung Internet Android 不支持 No |
safe
and
unsafe
|
Chrome
不支持
No
注意事项
|
Edge
不支持
No
注意事项
|
Firefox 完整支持 63 | IE 不支持 No |
Opera
不支持
No
注意事项
|
Safari
不支持
No
注意事项
|
WebView Android
不支持
No
注意事项
|
Chrome Android
不支持
No
注意事项
|
Firefox Android 完整支持 63 |
Opera Android
不支持
No
注意事项
|
Safari iOS
不支持
No
注意事项
|
Samsung Internet Android
不支持
No
注意事项
|
start
and
end
|
Chrome 完整支持 57 | Edge 完整支持 79 | Firefox 完整支持 45 | IE 不支持 No | Opera 完整支持 44 | Safari 不支持 No | WebView Android 完整支持 57 | Chrome Android 完整支持 57 | Firefox Android 完整支持 45 | Opera Android 完整支持 43 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 7.0 |
stretch
|
Chrome 完整支持 57 | Edge 完整支持 79 | Firefox 完整支持 52 | IE 不支持 No | Opera 完整支持 44 | Safari 不支持 No | WebView Android 完整支持 57 | Chrome Android 完整支持 57 | Firefox Android 完整支持 52 | Opera Android 完整支持 43 | Safari iOS 不支持 No | Samsung Internet Android 完整支持 7.0 |
完整支持
不支持
见实现注意事项。
用户必须明确启用此特征。
要求使用供应商前缀或不同名称。
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Supported in Grid Layout | Chrome 完整支持 57 | Edge 完整支持 16 | Firefox 完整支持 52 |
IE
部分支持
10
Prefixed
注意事项
|
Opera 完整支持 44 | Safari 完整支持 10.1 | WebView Android 完整支持 57 | Chrome Android 完整支持 52 | Firefox Android 完整支持 52 | Opera Android 完整支持 43 | Safari iOS 完整支持 10.3 | Samsung Internet Android 完整支持 6.2 |
完整支持
部分支持
见实现注意事项。
要求使用供应商前缀或不同名称。
align-items
property