Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒子模型提供最大的灵活性。 任何一个容器(盒子)都可以为其指定 Flex 布局。
#box{ display:flex; }
.box{ display:flex; }
Flex 的属性为六种
1:flex-direction 2:flex-wrap 3:flex-flow 4:justify-content 5:align-items 6:align-content
有四个值
row(默认值):效果为水平方向,起点在左端。
1 2 3
row-reverse:效果为水平方向,起点在右端
3 2 1
column:效果为垂直方向,起点在上方。
1
2
3
column-reverse:效果为垂直方向,起点在下方。
3
2
1
(1) flex-direction: row;
#box{ display:flex; flex-direction: row; }
(2) flex-direction: row-reverse;
#box{ display:flex; flex-direction: row-reverse; }
(3) flex-direction: column ;
#box{ display:flex; flex-direction: column; }
(4) flex-direction: column-reverse ;
#box{ display:flex; flex-direction: column-reverse; }
- 有三个值
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5 6 7 8
9 10 11 12
9 10 11 12
1 2 3 4 5 6 7 8
(1) flex-wrap: nowrap;
.box{ display:flex; flex-wrap: nowrap ; }
(2) flex-wrap: nowrap;
.box{ display:flex; flex-wrap: wrap ; }
(3) flex-wrap: nowrap;
.box{ display:flex; flex-wrap: wrap ; }
.box{ display:flex; flex-flow: row-reverse wrap ; }
123
123
123
1 2 3
1 2 3
(1)justify-content: flex-start
.box{ display:flex; justify-content: flex-start ; }
(2)justify-content:flex-end
.box{ display:flex; justify-content: flex-end ; }
(3)justify-content:center
.box{ display:flex; justify-content: center ; }
(4)justify-content:space-between
.box{ display:flex; justify-content: space-between ; }
(5)justify-content:space-around
.box{ display:flex; justify-content:space-around ; }
(1)align-items: flex-start;
.box{ display:flex; align-items: flex-start; }
(2)align-items: flex-end;
.box{ display:flex; align-items: flex-end; }
(3)align-items: center;
.box{ display:flex; align-items: center; }
(4)align-items: baseline;
.box{ display:flex; align-items: baseline; }
(5)align-items: stretch;
.box{ display:flex; align-items: stretch; }
(1)align-content: flex-start ;
.box{ display:flex; align-content: flex-start; }
(2)align-content: flex-end;
.box{ display:flex; align-content: flex-end; }
(3)align-content:center ;
.box{ display:flex; align-content:center ; }
(4)align-content:space-between ;
.box{ display:flex; align-content:space-between ; }
(5)align-content: space-aroun ;
.box{ display:flex; align-content: space-aroun ; }
(6)align-content: stretch ;
.box{ display:flex; align-content: stretch; }