flexbox的核心是自适应动态变化的弹性布局web
伸缩布局盒模型和术语布局
主轴
main axis:Flex容器的主轴主要用来配置Flex项目。注意,它不必定是水平,这主要取决于flex-direction属性。
main-start | main-end:Flex项目的配置从容器的主轴起点边开始,往主轴终点边结束。
main size:Flex项目的在主轴方向的宽度或高度就是项目的主轴长度,Flex项目的主轴长度属性是width或height属性,由哪个对着主轴方向决定。flex
侧轴
cross axis:与主轴垂直的轴称做侧轴,是侧轴方向的延伸。
cross-start | cross-end:伸缩行的配置从容器的侧轴起点边开始,往侧轴终点边结束。
cross size:Flex项目的在侧轴方向的宽度或高度就是项目的侧轴长度,Flex项目的侧轴长度属性是width或height属性,由哪个对着侧轴方向决定。flexbox
设置父容器的属性有spa
.container{ display: flex | inline-flex; flex-direction: row | row-reverse | column | column-reverse; flex-wrap: nowrap | 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 | strtch; align-content: flex-start | flex-end | center | space-between | space-around | stretch; }
设置子元素的属性有code
.item{ order: number; flex-grow: number; /* default 0 */ flex-shrink: number; /* default 1 */ flex-basis: number | auto; /* default auto */ flex: none | @flex-grow @flex-shrink @flex-basis; align-self: auto | flex-start | flex-end | center | baseline | stretch; }
flex-direction 显示方向blog
.container{
display: flex;
flex-direction: row | row-reverse | column | column-reverse;
}rem
flex-wrap 伸缩行换行it
.container{ display: flex; flex-wrap: nowrap | wrap | wrap-reverse; }
flex-flow 伸缩方向与换行 flex-flow 是 flex-direction 和 flex-wrap 的缩写io
.flex-container { -webkit-flex-flow: column nowrap; flex-flow: column nowrap; }
justify-content 主轴对齐
.container { justify-content: flex-start | flex-end | center | space-between | space-around; }
align-items 侧轴对齐
.container { align-items: flex-start | flex-end | center | baseline | stretch; }
align-content 堆栈伸缩行(该属性只针对父容器内多行的状况,如设置了flex-wrap:wrap;属性断行)
.container { align-content: flex-start | flex-end | center | space-between | space-around | stretch; }
order 显示顺序,数值小的排在前面。能够为负值。
.item { order: <integer>; }
flex
.item { flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ] //默认状况下,flex的值是 }0 1 auto;
float,clear和vertical-align属性在Flex项目中无效
flex-shrink: 0;固定大小,不会收缩
flex-basis属性告诉父容器,在剩余空间被分配以前先定义子元素的默认尺寸,能够指定为百分比或rem等长度单位或者auto关键字。
flex-basis: 0将父容器的所有空间按比例分配到每一个子元素上,下面咱们就来为每一个子元素添加flex-basis: 0属性:
align-self 单个项目的侧轴对齐(它的值和 align-items 同样)
.item { align-self: auto | flex-start | flex-end | center | baseline | stretch; }