flex屬性
一、flex屬性的歸納
flex-direction flex-wrap flex-flow justify-content align-items align-content
1.1 flex-direction屬性:
flex-direction: row / row-reverse / column /column-reverse
row(默認值):主軸為水平方向,起點在左端。 row-reverse:主軸為水平方向,起點在右端。 column:主軸為垂直方向,起點在上沿。 column-reverse:主軸為垂直方向,起點在下沿。
1.2 flex-wrap屬性:
flex-wrap: wrap / nowrap / wrap-reverse
nowrap(默認):不換行 wrap:換行,第一行在上方 wrap-reverse:換行,第一行在下方
1.3 flex-flow屬性:
flex-flow
屬性是flex-direction
屬性和flex-wrap
屬性的簡寫形式,默認值為row nowrap
1.4 justify-content屬性:
justify-content: flex-start | flex-end | center | space-between | space-around
flex-start(默認值):左對齊 flex-end:右對齊 center: 居中 space-between:兩端對齊,項目之間的間隔都相等 space-around:每個項目兩側的間隔相等。所以,項目之間的間隔比項目與邊框的間隔大一倍
1.5 align-items屬性:
align-items: flex-start | flex-end | center | baseline | stretch
lex-start:交叉軸的起點對齊。 flex-end:交叉軸的終點對齊。 center:交叉軸的中點對齊。 baseline: 項目的第一行文字的基線對齊。 stretch(默認值):如果項目未設置高度或設為auto,將占滿整個容器的高度。
1.6 align-content屬性:
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
flex-start:與交叉軸的起點對齊。 flex-end:與交叉軸的終點對齊。 center:與交叉軸的中點對齊。 space-between:與交叉軸兩端對齊,軸線之間的間隔平均分布。 space-around:每根軸線兩側的間隔都相等。所以,軸線之間的間隔比軸線與邊框的間隔大一倍。 stretch(默認值):軸線占滿整個交叉軸。
二、項目常用屬性:
order flex-grow flex-shrink flex-basis flex align-self
2.1 order屬性
order
屬性定義項目的排列順序。數值越小,排列越靠前,默認為0
2.1 flex-grow
flex-grow
屬性定義項目的放大比例,默認為0
,即如果存在剩余空間,也不放大
2.3 flex-shrink屬性
flex-shrink
屬性定義了項目的縮小比例,默認為1,即如果空間不足,該項目將縮小
2.4 flex-basic屬性
flex-basis
屬性定義了在分配多余空間之前,項目占據的主軸空間(main size)。瀏覽器根據這個屬性,計算主軸是否有多余空間。它的默認值為auto
,即項目的本來大小
2.5 flex屬性
flex
屬性是flex-grow
, flex-shrink
和 flex-basis
的簡寫,默認值為0 1 auto
。後兩個屬性可選。
2.6 align-self屬性
align-self
屬性允許單個項目有與其他項目不一樣的對齊方式,可覆蓋align-items
屬性。默認值為auto
,表示繼承父元素的align-items
屬性,如果沒有父元素,則等同於stretch
align-self: auto | flex-start | flex-end | center | baseline | stretch;
除了auto,其他和align-items
屬性一樣
flex屬性