目录

style alignSelf 属性

示例

设置灵活元素内的其中一项的对齐方式以适合容器:

document.getElementById("myBlueDiv").style.alignSelf = "stretch";
亲自试一试 »

描述

alignSelf 属性指定灵活容器内所选项目的对齐方式。

笔记:alignSelf 属性覆盖灵活容器的alignItems 属性。


语法

返回alignSelf属性:

object.style.alignSelf

设置alignSelf属性:

object.style.alignSelf = "auto|stretch|center|flex-start|flex-end|baseline|initial|inherit"

属性值

Value Description
auto Default. The element inherits its parent container's align-items property, or "stretch" if it has no parent container
stretch The element is positioned to fit the conatiner
center The element is positioned at the center of the container
flex-start The element is are positioned at the beginning of the container
flex-end The element is positioned at the end of the container
baseline The element is positioned at the baseline of the container
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

技术细节

默认值: 汽车
返回值: 一个字符串,表示元素的align-self属性
CSS版本 CSS3

浏览器支持

alignSelf是 CSS3 (1999) 的一项功能。

所有浏览器都完全支持它:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 11

相关页面

CSS 参考:自我对齐属性

HTML DOM 样式参考:对齐内容属性

HTML DOM 样式参考:对齐项目属性