這一章節(jié)我們來學(xué)習(xí)align-items屬性,本屬性定義了項(xiàng)目在交叉軸上的對(duì)齊方式。屬性值分別為:
align-items: flex-start | flex-end | center | baseline | stretch;
結(jié)合右側(cè)編輯器中的布局以及下面的樣式設(shè)置進(jìn)行理解:
flex-start
:默認(rèn)值,左對(duì)齊
.box { height: 700px; background: blue; display: flex; align-items: flex-start; }
實(shí)現(xiàn)效果:
flex-end
:交叉軸的終點(diǎn)對(duì)齊
.box { height: 700px; background: blue; display: flex; align-items: flex-end; }
實(shí)現(xiàn)效果:
center
: 交叉軸的中點(diǎn)對(duì)齊
.box { height: 700px; background: blue; display: flex; align-items: center; }
實(shí)現(xiàn)效果:
baseline
:項(xiàng)目的第一行文字的基線對(duì)齊。
.box { height: 700px; background: blue; display: flex; align-items: baseline; }
三個(gè)盒子中設(shè)置不同的字體大小,可以參考右側(cè)編輯器中的代碼進(jìn)行測(cè)試。
實(shí)現(xiàn)效果:
stretch(默認(rèn)值)
:如果項(xiàng)目未設(shè)置高度或設(shè)為auto,將占滿整個(gè)容器的高度。
.box { height: 300px; background: blue; display: flex; align-items: stretch; } .box div { /*不設(shè)置高度,元素在垂直方向上鋪滿父容器*/ width: 200px; }
實(shí)現(xiàn)效果:
自己按照上面的代碼測(cè)試,感受下各個(gè)屬性值實(shí)現(xiàn)的樣式。
請(qǐng)驗(yàn)證,完成請(qǐng)求
由于請(qǐng)求次數(shù)過多,請(qǐng)先驗(yàn)證,完成再次請(qǐng)求
打開微信掃碼自動(dòng)綁定
綁定后可得到
使用 Ctrl+D 可將課程添加到書簽
舉報(bào)