本文實例講述了微信小程序Flex布局用法。分享給大家供大家參考,具體如下:
Flex布局: Flexible Box的縮寫,意為“彈性布局”,為盒模型提供巨大的靈活性
使用說明:
1. 任何容器都可以使用flex布局
.box { display: flex;}2.行內元素可以使用flex布局
.box{ display: inline-flex;}3.webkit內核的瀏覽器,要加上-webkit前綴
.box { display: -webkit-flex; /* Safari */ display: flex;}外層flex容器的屬性:
1.flex-direction屬性
.box { flex-direction: row | row-reverse | column | column-reverse;}row(默認值):主軸為水平方向,起點在左端。
row-reverse:主軸為水平方向,起點在右端。
column:主軸為垂直方向,起點在上沿。
column-reverse:主軸為垂直方向,起點在下沿。
2.flex-wrap屬性
.box{ flex-wrap: nowrap | wrap | wrap-reverse;}nowrap (默認值) :不換行。
wrap:換行,第一行在上方。
wrap-reverse:換行,第一行在下方。
3. flex-flow屬性:是flex-direction屬性和flex-wrap屬性的簡寫形式,默認值為row nowrap
.box { flex-flow: <flex-direction> || <flex-wrap>;}4. justify-content屬性:定義item在主軸上的對其方式
.box { justify-content: flex-start | flex-end | center | space-between | space-around;}flex-start(默認值):左對齊
flex-end:右對齊
center: 居中
space-between:兩端對齊,項目之間的間隔都相等。
space-around:每個項目兩側的間隔相等。所以,項目之間的間隔比項目與邊框的間隔大一倍。
5. align-items屬性:定義項目在交叉軸上如何對其
.box { align-items: flex-start | flex-end | center | baseline | stretch;}flex-start:交叉軸的起點對齊。
flex-end:交叉軸的終點對齊。
center:交叉軸的中點對齊。
baseline: 項目的第一行文字的基線對齊。
stretch(默認值):如果項目未設置高度或設為auto,將占滿整個容器的高度。
6. align-content屬性:定義多跟軸線的對其方式,如果只有一根軸線則不起作用
.box { align-content: flex-start | flex-end | center | space-between | space-around | stretch;}flex-start:與交叉軸的起點對齊。
flex-end:與交叉軸的終點對齊。
center:與交叉軸的中點對齊。
space-between:與交叉軸兩端對齊,軸線之間的間隔平均分布。
space-around:每根軸線兩側的間隔都相等。所以,軸線之間的間隔比軸線與邊框的間隔大一倍。
新聞熱點
疑難解答