Kailang Blog

Flex 布局2020-12-17Θ

flex header

容器属性#

有 6 个属性设置在容器上

  • flex-direction => row | row-reverse | column | column-reverse
  • flex-wrap 是否换行 => nowrap | wrap | wrap-reverse
  • flex-flow

flex-flow 属性是 flex-direction 属性和 flex-wrap 属性的简写形式,默认值为 row nowrap。

  • 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

项目属性#

有 6 个

  • order 定义项目的排列顺序。数值越小,排列越靠前,默认为 0;
  • flex-grow 放大比例,默认为0,即如果存在剩余空间,也不放大;
  • flex-shrink 缩小比例,默认为1,即如果空间不足,该项目将缩小;
  • flex-basis 项目占据的主轴空间;
  • flex flex 属性是 flex-grow, flex-shrink 和 flex-basis 的简写,默认值为 0 1 auto;
  • align-self 项目有与其他项目不一样的对齐方式。

实时调试#

flex-grow、flex-shrink#

1
2
3

flex-wrap#

1
2
3
4
5

flex-direction#

1
2
3

align-items、align-self#

1
2
3
4
5

父元素 align-items:

子元素 align-self:

align-content#

1
2
3
4
5

justify-content#

1
2
3

文档#