flex-direction 旋转的主轴,与它垂直的交叉轴属性名分两套:justify-content 永远管主轴,align-* 永远管交叉轴。direction 从 row 改成 column,两者的表现会跟着互换 —— 这是 Flex 最大的困惑来源,用图记住而不是背。
row-reverse 会同时反转视觉阅读顺序,对读屏器和 Tab 顺序没有影响,可能造成「看到的顺序与听到的顺序不一致」,慎用。
只有当容器有剩余空间时它们才有区别;子项已经铺满时全都长一样。
.list { display: flex; gap: 12px 20px; } /* 行间距 列间距;也可写 gap: 12px 同时生效 */
/* gap 只加在「相邻之间」,不会给首尾多出空白 —— 从此不需要 :last-child { margin-right: 0 } */
/* gap 同样适用于 grid 与多列 flex-wrap(换行时行间距也归它管) */
/* 水平居中 */ .c { display: flex; justify-content: center; }
/* 垂直居中 */ .c { display: flex; align-items: center; }
/* 完全居中 */ .c { display: flex; align-items: center; justify-content: center; }
/* 完全居中(grid 一行搞定) */ .c { display: grid; place-items: center; }
/* 左右两端 */ .bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
/* 一列纵向 */ .col { display: flex; flex-direction: column; gap: 8px; }