flex布局
一、属性
关于flex常用的属性,我们可以划分为容器属性和容器成员属性
1、容器属性有:
- flex-direction:项目元素方向
- flex-wrap:项目是否换行
- flex-flow:是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap
- justify-content:设置弹性盒子中元素在主轴(横轴)方向上的对齐方式
- align-items:设置弹性盒子中元素在侧轴(纵轴)方向上的对齐方式
- align-content:定义了多根轴线的对齐方式(纵轴)。如果项目只有一根轴线,该属性不起作用
.container {
flex-direction: row | row-reverse | column | column-reverse;
flex-wrap: nowrap | wrap | wrap-reverse; //:wrap换行,第一行在下方 ;wrap-reverse:换行,第一行在上方
flex-flow: <flex-direction> || <flex-wrap>;
justify-content: flex-start | flex-end | center | space-between | space-around;
align-items: flex-start | flex-end | center | baseline | stretch;
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
}
2、容器成员属性如下:
- order:定义项目的排列顺序。数值越小,排列越靠前,默认为0
- flex-grow:定义项目的放大比例(容器宽度>元素总宽度时如何伸展);上面讲到当容器设为flex-wrap: nowrap;不换行的时候,容器宽度有不够分的情况,弹性元素会根据flex-grow来决定
- flex-shrink:定义了项目的缩小比例(容器宽度<元素总宽度时如何收缩),默认为1,即如果空间不足,该项目将缩小
- flex-basis:设置的是元素在主轴上的初始尺寸,所谓的初始尺寸就是元素在flex-grow和flex-shrink生效前的尺寸;
- flex:flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto
- align-self:默认值为auto;表示继承父元素的align-items属性,如果没有父元素,则等同于stretch;允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性
.item {
order: <integer>; //默认为0
flex-grow: <number>; //默认为0,即如果存在剩余空间,也不放大
flex-shrink: <number>; /* default 1 */
flex-basis: <length> | auto;//默认值为auto,即项目的本来大小,如设置了width则元素尺寸由width/height决定(主轴方向),没有设置则由内容决定
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
align-self: auto | flex-start | flex-end | center | baseline | stretch;
}

浙公网安备 33010602011771号