弹性布局学习 阮一峰博客
如何开启弹性布局 开启弹性布局的标签即为”容器“
.box{
display: -webkit-flex; /* Safari Webkit 内核的浏览器,必须加上-webkit前缀。 */
display: flex;
display: inline-flex; /* 行内元素开启弹性布局*/
、、、兼容写法、、、
display:-webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
、、、、、、
容器具有是属性
flex-direction 决定主轴的方向
flex-wrap 容器排布在一条线(轴线)上,当排布满的是否换行
flex-flow 是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap
justify-content 定义了在主轴上的对齐方式
align-items 定义了在交叉轴上如何对齐。
align-content 定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用
flex-direction具有的属性
.box {
flex-direction: row | row-reverse | column | column-reverse;
}
row(默认值):主轴为水平方向,起点在左端。
、、、兼容写法、、、
box-orient:horizontal;
box-direction:normal;
-webkit-box-orient:horizontal;
-webkit-box-direction:normal;
-moz-box-orient:horizontal;
-moz-box-direction:normal;
flex-direction:row;
-webkit-flex-direction:row;
、、、、、、
row-reverse:主轴为水平方向,起点在右端。
、、、兼容写法、、、
box-orient:horizontal;
box-direction:reverse;
-webkit-box-orient:horizontal;
-webkit-box-direction:reverse;
-moz-box-orient:horizontal;
-moz-box-direction:reverse;
flex-direction:row-reverse;
-webkit-flex-direction:row-reverse;
、、、、、、
column:主轴为垂直方向,起点在上沿。
、、、兼容写法、、、
-webkit-box-orient:vertical;
-webkit-box-direction:normal;
-moz-box-orient:vertical;
-moz-box-direction:normal;
flex-direction:column;
-webkit-flex-direction:column;
、、、、、、
column-reverse:主轴为垂直方向,起点在下沿。
、、、兼容写法、、、
-webkit-box-orient:vertical;
-webkit-box-direction:reverse;
-moz-box-orient:vertical;
-moz-box-direction:reverse;
box-orient:vertical;
box-direction:reverse;
flex-direction:column-reverse;
-webkit-flex-direction:column-reverse;
、、、、、、
flex-wrap 具有的属性
.box {
flex-wrap: nowrap | wrap | wrap-reverse;
}
nowrap(默认):不换行
-webkit-flex-wrap:nowrap;
-webkit-box-lines:single;
-moz-flex-wrap:nowrap;
flex-wrap:nowrap;
wrap:换行,第一行在上方。
、、、兼容写法、、、
-webkit-flex-flow:row wrap;
-webkit-box-orient:horizontal;
-webkit-box-lines:multiple;
-moz-flex-flow:row wrap;
box-orient:horizontal;
box-lines:multiple;
flex-flow:row wrap;
、、、、、、
wrap-reverse:换行,第一行在下方。
flex-flow 具有的属性
.box {
flex-flow: <flex-direction> || <flex-wrap>
}
justify-content 具有的属性
.box {
justify-content: flex-start | flex-end | center | space-between | space-around;
}
flex-start(默认值):左对齐
flex-end:右对齐
center: 据中对齐
、、、兼容写法、、、
-webkit-box-orient:vertical;
-webkit-box-direction:reverse;
-moz-box-orient:vertical;
-moz-box-direction:reverse;
box-orient:vertical;
box-direction:reverse;
flex-direction:column-reverse;
-webkit-flex-direction:column-reverse;
、、、、、、
space-between:两端对齐,项目之间的间隔都相等。
space-around:每个项目两侧的间隔相等。所以,项目之间的间隔比项目与边框的间隔大一倍。
align-items 具有的属性
.box {
align-items: flex-start | flex-end | center | baseline | stretch;
flex-start: 交叉轴(垂直方向)的起点对齐。
flex-end: 交叉轴垂直方向)的终点对齐。
center: 交叉轴垂直方向)的中点对齐。
、、、兼容写法、、、
align-items:center;
-webkit-align-items:center;
box-align:center;
-moz-box-align:center;
-webkit-box-align:center;
、、、、、、
baseline: 项目的【第一行文字】的基线对齐。
stretch (默认值):如果项目未设置高度或设为auto,将占满整个容器的高度。
align-conten 具有的属性
.box {
align-content: flex-start | flex-end | center | space-between | space-around | stretch;
}
flex-start:与交叉轴的起点对齐。
flex-end:与交叉轴的终点对齐。
center:与交叉轴的中点对齐。
space-between:与交叉轴两端对齐,轴线之间的间隔平均分布。
space-around:每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
stretch(默认值):轴线占满整个交叉轴。
项目(.box-child 子元素)具有是属性
order 定义项目的排列顺序。数值越小,排列越靠前,默认为0
flex-grow 定义项目的放大比例,默认为0,即如果存在剩余空间,也不放大
flex-shrink 定义了项目的缩小比例,默认为1,即如果空间不足,该项目将缩小
flex-basis 定义了在分配多余空间之前,项目占据的主轴空间(main size)。浏览器根据这个属性,计算主轴是否有多余空间。它的默认值为auto,即项目的本来大小
flex 是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选 【常用】
~~~
、、、兼容写法、、、
box-flex:num;
-webkit-box-flex:num;
-moz-box-flex:num;
flex:num;
-webkit-flex:num;
align-self align-self属性允许单个项目有与其他项目不一样的对齐方式,可覆盖align-items属性。默认值为auto,表示继承父元素的align-items属性,如果没有父元素,则等同于stretch
##### align-self 具有的属性
.box-child{
align-self: auto | flex-start | flex-end | center | baseline | stretch;
}
auto: ( 默认值)交叉轴的起点对齐。
flex-start: 交叉轴的起点对齐
flex-end: 交叉轴的终点对齐
center: 交叉轴的据中对齐
baseline 项目的第一行文字的基线对齐
stretch 轴线占满整个交叉轴