✨ Flexbox Layout Generator
Pick the key flex properties and immediately get the matching display:flex CSS with a live preview of one, two and three items.
📐 工作原理与说明
display: flex;flex-direction / flex-wrap / justify-content / align-items / gap 组合
把 flex-direction、wrap、justify-content、align-items、gap 等属性拼装为 display:flex 声明,并以 1 / 2 / 3 个项目实时演示排列效果;用于一维布局。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Main and cross axis | flex-direction sets the main axis, the cross axis stays perpendicular | CSS Flexible Box Layout Level 1 |
| Flex resolution | free space follows flex-grow weights, deficits follow flex-shrink | CSS Flexible Box Layout Level 1 |
| Alignment | justify-content handles the main axis, align-items the cross axis | CSS Flexible Box Layout Level 1 |
⚠️ 使用说明与注意事项
- justify-content 控制主轴(由 flex-direction 决定水平或垂直)上的对齐与分布。
- align-items 控制交叉轴上的对齐;stretch 会让项目拉伸填满交叉轴。
- flex-wrap:wrap 允许换行,配合 gap 可快速实现自适应网格。
🧩 flex 属性速查
| 属性 | 常用取值 | 说明 |
|---|---|---|
| flex-direction | row / column / row-reverse / column-reverse | 主轴方向 |
| justify-content | flex-start / center / flex-end / space-between / space-around / space-evenly | 主轴对齐 |
| align-items | stretch / flex-start / center / flex-end / baseline | 交叉轴对齐 |
| flex-wrap | nowrap / wrap / wrap-reverse | 是否换行 |
| gap | 任意长度(如 12px) | 项目间距 |
提示:要让单个项目在交叉轴居中可用 align-self;要控制项目伸缩用 flex: 1 或 flex-grow/shrink/basis。