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;
}
(1)nowrap(默认):不换行。
(2)wrap:换行,第一行在上方。
(3)wrap-reverse:换行,第一行在下方。
3、flex-flow(flex-direction和flex-wrap的结合),默认值为row nowrap。
.box {
flex-flow: row || nowrap;
}
常用的flex布局:
1、justify-content 主轴布局
.box {
justify-content: flex-start | flex-end | center | space-between | space-around;
}
2、align-items 交叉轴布局
.box {
align-items: flex-start | flex-end | center | baseline | stretch;
}
3、align-content(定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用。)
.box {
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
}
flex-start:与交叉轴的起点对齐。
flex-end:与交叉轴的终点对齐。
center:与交叉轴的中点对齐。
space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
stretch(默认值):轴线占满整个交叉轴。