一 初识flex
- 开启flex布局的元素叫 flex container
flex container里面的子元素叫做 flex items - 开启flex布局(两种)
display:flex
display:inline-flex
- flex模型有两个轴 main axis(主轴)和 cross axis(侧轴)这两个轴的方向可以改变(通过flex-direction)
- flex items默认沿着main axis(主轴)方向排列
二 flex container上的CSS
1. flex-direction(决定main axis的方向)
flex-direction: row
flex-direction: row-reverse
flex-direction: column
flex-direction: column-reverse
2. justify-content(决定flex items 在main axis的对齐方式)
justify-content: flex-start
justify-content: flex-end
justify-content: space-between
justify-content: space-evenly
justify-content: space-around
3. align-content(决定flex items 在cross axis上的对齐方式)
align-content: stretch
align-content: normal
align-content: flex-start
align-content: flex-end
align-content: center
align-content: space-between
align-content: space-around
align-content: space-evenly
4. align-items(决定flex items在cross axis的对齐方式)
align-items: normal
align-items: stretch
align-items: flex-start
align-items: flex-end
align-items: center
align-items: baseline
5. flex-wrap(决定flex items 单行还是多行)
flex-wrap: nowrap
flex-wrap: wrap
flex-wrap: wrap-reverse
6. flex-flow(flex-direction和flex-wrap的缩写,顺序随意)
flex-flow: row-reverse wrap
三 flex items上的CSS
1. order
order: 10
2. align-self(覆盖align-items的设置)
align-self: normal
align-self: stretch
align-self: flex-start
align-self: flex-end
align-self: center
align-self: baseline
3. flex-grow(扩展main axis的剩余间隙)
flex-grow: 2
flex-grow: 0.2
4. flex-shrink(收缩main axis的超出部分)
flex-grow: 2
flex-grow: 0.2
5. flex-basis(重新设置main axis方向上的base size)
flex-basis: 200px
5. flex(felx-grow/shrink/basis的缩写,可指定1/2/3个值)
flex: 1
flex: 100px