开启 Flex

.container {
  display: flex;      /* 容器 */
}

容器内的直接子元素变成 flex item,沿主轴排列,默认水平。

主轴对齐

justify-content: flex-start | center | space-between | space-around

交叉轴对齐

align-items: stretch | center | flex-start | flex-end

换行与方向

flex-wrap: wrap;     /* 放不下换行 */
flex-direction: column;  /* 主轴变纵向 */

弹性比例

.item1 { flex: 1; }   /* 占 1 份 */
.item2 { flex: 2; }   /* 占 2 份 */
/* 经典三栏:左 1 右 1 中间自适应 */
.middle { flex: 1; }

水平垂直居中(三行)

.center {
  display: flex;
  justify-content: center;
  align-items: center;
}

典型导航栏

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
记忆:justify 管主轴、align 管交叉轴。flex: 1 是 flex-grow:1; flex-shrink:1; flex-basis:0% 的简写。