Style alignSelf 屬性

定義和用法

alignSelf 屬性規定彈性容器內選定項的對齊方式。

注釋:alignSelf 屬性會覆蓋彈性容器的 alignItems 屬性

實例

為彈性元素內的其中一項設置對齊方式,以適應容器:

document.getElementById("myBlueDiv").style.alignSelf = "stretch";

親自試一試

語法

返回 alignSelf 屬性:

object.style.alignSelf

設置 alignSelf 屬性:

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

屬性值

描述
auto 默認。元素繼承其父容器的 align-items 屬性,如果沒有父容器,則為 "stretch"。
stretch 元素被拉伸以適應容器。
center 元素位于容器的中心。
flex-start 元素位于容器的開頭。
flex-end 元素位于容器的末尾。
baseline 元素位于容器的基線。
initial 將此屬性設置為其默認值。請參閱 initial
inherit 從其父元素繼承此屬性。請參閱 inherit

技術細節

默認值: auto
返回值: 字符串,表示元素的 align-self 屬性
CSS 版本: CSS3

瀏覽器支持

alignItems 是 CSS3 (1999) 特性。

所有瀏覽器都完全支持它:

Chrome Edge Firefox Safari Opera IE
Chrome Edge Firefox Safari Opera IE
支持 支持 支持 支持 支持 11

相關頁面

CSS 參考手冊:align-self 屬性

HTML DOM STYLE 參考手冊:alignContent 屬性

HTML DOM STYLE 參考手冊:alignItems 屬性