flex布局常⽤参数
flexible box 弹性布局
dispaly:flex
flex-direction属性决定主轴的⽅向(即项⽬的排列⽅向)。
.box{flex-direction: row | row-reverse | column | column-reverse;}
它可能有4个值。
row(默认值):主轴为⽔平⽅向,起点在左端。
row-reverse:主轴为⽔平⽅向,起点在右端。
column:主轴为垂直⽅向,起点在上沿。
column-reverse:主轴为垂直⽅向,起点在下沿。
flex-wrap属性定义,如果⼀条轴线排不下,如何换⾏。
.
box{flex-wrap: nowrap | wrap | wrap-reverse;}
它可能取三个值。
(1)nowrap(默认):不换⾏。
(2)wrap:换⾏,第⼀⾏在上⽅。
flex布局详细讲解
(3)wrap-reverse:换⾏,第⼀⾏在下⽅。
flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap。
flex-flow: <flex-direction> || <flex-wrap>;
justify-content属性定义了项⽬在主轴上的对齐⽅式。
.box{justify-content: flex-start | flex-end | center | space-between | space-around;}
它可能取5个值,具体对齐⽅式与轴的⽅向有关。下⾯假设主轴为从左到右。
flex-start(默认值):左对齐
flex-end:右对齐
center: 居中
space-between:两端对齐,项⽬之间的间隔都相等。
space-around:每个项⽬两侧的间隔相等。所以,项⽬之间的间隔⽐项⽬与边框的间隔⼤⼀倍。
align-items属性定义项⽬在交叉轴上如何对齐。
.box{align-items: flex-start | flex-end | center | baseline | stretch;}
它可能取5个值。具体的对齐⽅式与交叉轴的⽅向有关,下⾯假设交叉轴从上到下。
flex-start:交叉轴的起点对齐。
flex-end:交叉轴的终点对齐。
center:交叉轴的中点对齐。
baseline: 项⽬的第⼀⾏⽂字的基线对齐。
stretch(默认值):如果项⽬未设置⾼度或设为auto,将占满整个容器的⾼度。
align-content属性定义了多根轴线的对齐⽅式。如果项⽬只有⼀根轴线,该属性不起作⽤。
.box{align-content: flex-start | flex-end | center | space-between | space-around | stretch;}
该属性可能取6个值。
flex-start:与交叉轴的起点对齐。
flex-end:与交叉轴的终点对齐。
center:与交叉轴的中点对齐。
space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔⽐轴线与边框的间隔⼤⼀倍。
stretch(默认值):轴线占满整个交叉轴。
四、项⽬的属性
以下6个属性设置在项⽬上。
order
flex-grow
flex-shrink
flex-basis
flex
align-self
align-self属性允许单个项⽬有与其他项⽬不⼀样的对齐⽅式,可覆盖align-items属性。
默认值为auto,表⽰继承⽗元素的align-items属性,如果没有⽗元素,则等同于stretch。.item{align-self: auto | flex-start | flex-end | center | baseline | stretch;}