align-self

This translation is incomplete. Please help translate this article from English

概述

CSS 属性 align-self 会对齐当前 flex 行中的 flex 元素,并覆盖已有的align-items 的值. 如果任何 flex 元素的侧轴方向 margin 值设置为 auto,则会忽略 align-self。In Grid, it aligns the item inside the grid area. 在Flexbox中会按照cross axis (当前flex 元素排列方向的垂直方向) 进行排列.

初始值auto
适用元素flex items, grid items, and absolutely-positioned boxes
是否是继承属性
适用媒体visual
计算值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.
Animation typediscrete
正规顺序the unique non-ambiguous order defined by the formal grammar

可以参考 使用 CSS 弹性框 获取更多信息。

语法

align-self: auto
align-self: flex-start
align-self: flex-end
align-self: center
align-self: baseline
align-self: stretch

align-self: inherit

auto
设置为父元素的 align-items 值,如果该元素没有父元素的话,就设置为 stretch
flex-start
flex 元素会对齐到 cross-axis 的首端。
flex-end
flex 元素会对齐到 cross-axis 的尾端。
center
flex 元素会对齐到 cross-axis 的中间,如果该元素的 cross-size 的尺寸大于 flex 容器,将在两个方向均等溢出。
baseline
所有的 flex 元素会沿着基线对齐,The item with the largest distance between its cross-start margin edge and its baseline is flushed with the cross-start edge of the line。
stretch
flex 元素将会基于容器的宽和高,按照自身 margin box 的 cross-size 拉伸。

语法格式

Formal syntax: 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

规范

Specification Status Comment
CSS Box Alignment Module Level 3
align-self
Working Draft

浏览器兼容性

在 Flex 布局中的兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Supported in Flex LayoutChrome Full support 36
Full support 36
Partial support 29
Notes
Notes Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
Full support 21
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Edge Full support 12Firefox Full support 20
Notes
Full support 20
Notes
Notes Before Firefox 27, only single-line flexbox is supported.
No support 18 — 20
Disabled
Disabled From version 18 until version 20 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Full support 49
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Full support 48
Prefixed Disabled
Prefixed Implemented with the vendor prefix: -webkit-
Disabled From version 48: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE Full support 11Opera Full support 12.1Safari Full support 9
Full support 9
Full support 6.1
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
WebView Android Full support 37
Full support 37
Partial support 4.4
Notes
Notes Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
Full support ≤37
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Chrome Android Full support 36
Full support 36
Partial support 29
Notes
Notes Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Chrome 52.
Full support 25
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Firefox Android Full support 20
Notes
Full support 20
Notes
Notes Before Firefox 27, only single-line flexbox is supported.
No support 18 — 20
Disabled
Disabled From version 18 until version 20 (exclusive): this feature is behind the layout.css.flexbox.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Full support 49
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Full support 48
Prefixed Disabled
Prefixed Implemented with the vendor prefix: -webkit-
Disabled From version 48: this feature is behind the layout.css.prefixes.webkit preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 12.1Safari iOS Full support 9
Full support 9
Full support 6.1
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
Samsung Internet Android Full support 3.0
Full support 3.0
Partial support 2.0
Notes
Notes Older versions of the specification treat absolute positioned children as though they are a 0 by 0 flex item. Later specification versions take the children out of the flow and set their positions based on align and justify properties. Chrome implements the new behavior beginning with Samsung Internet 6.0.
Full support 1.5
Prefixed
Prefixed Implemented with the vendor prefix: -webkit-
baselineChrome Full support 57Edge No support NoFirefox Full support 45IE No support NoOpera Full support 44Safari No support NoWebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 45Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 7.0
first baseline and last baselineChrome Full support 57Edge No support NoFirefox Full support 52IE No support NoOpera Full support 44Safari No support NoWebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 7.0
left and rightChrome No support NoEdge No support NoFirefox Full support 52IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android Full support 52Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
safe and unsafeChrome No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
Edge No support NoFirefox Full support 63IE No support NoOpera No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
Safari No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
WebView Android No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
Chrome Android No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
Firefox Android Full support 63Opera Android No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
Safari iOS No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
Samsung Internet Android No support No
Notes
No support No
Notes
Notes This value is recognized, but has no effect.
start and endChrome Full support 57Edge No support NoFirefox Full support 45IE No support NoOpera Full support 44Safari No support NoWebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 45Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 7.0
stretchChrome Full support 57Edge No support NoFirefox Full support 52IE No support NoOpera Full support 44Safari No support NoWebView Android Full support 57Chrome Android Full support 57Firefox Android Full support 52Opera Android Full support 43Safari iOS No support NoSamsung Internet Android Full support 7.0

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

在 Grid 布局中的兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Supported in Grid LayoutChrome Full support 57Edge Full support 16Firefox Full support 52IE Partial support 10
Prefixed Notes
Partial support 10
Prefixed Notes
Prefixed Implemented with the vendor prefix: -ms-
Notes IE10 and 11 have the property -ms-grid-column-align which acts in a similar way to align-self.
Opera Full support 44Safari Full support 10.1WebView Android Full support 57Chrome Android Full support 52Firefox Android Full support 52Opera Android Full support 43Safari iOS Full support 10.3Samsung Internet Android Full support 6.2

Legend

Full support  
Full support
Partial support  
Partial support
See implementation notes.
See implementation notes.
Requires a vendor prefix or different name for use.
Requires a vendor prefix or different name for use.

参考