跳到主要内容

Flexbox 生成器

直观调整真实的弹性布局。设置容器和各个项目,尝试不同宽度,然后获取 CSS、HTML 或 Tailwind 代码。

实时预览

960 × 320 px · 选择预览中的项目以进行编辑。

项目 1
项目 2
项目 3

项目

最多 12 个项目,至少保留一个。

.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: stretch;
  align-content: stretch;
  gap: 16px;
  padding: 24px;
  height: 320px;
  box-sizing: border-box;
}

.item-1 {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 180px;
  order: 0;
  align-self: auto;
  min-width: 0;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 12px;
  overflow-wrap: anywhere;
  background: #dbeafe;
  color: #172554;
}

.item-2 {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 180px;
  order: 0;
  align-self: auto;
  min-width: 0;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 12px;
  overflow-wrap: anywhere;
  background: #bfdbfe;
  color: #172554;
}

.item-3 {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 180px;
  order: 0;
  align-self: auto;
  min-width: 0;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 12px;
  overflow-wrap: anywhere;
  background: #93c5fd;
  color: #172554;
}

所有操作均在您的浏览器中完成。

使用方法

  1. 选择布局模板,或从卡片示例开始。
  2. 调整容器,并选择一个项目来编辑其大小、顺序和对齐方式。
  3. 尝试桌面、平板和手机宽度,然后复制生成的代码。

示例

display: flex;
flex-wrap: wrap;
gap: 16px;

功能与限制

预览和导出使用相同的布局样式,包括 320 px 的容器高度和 24 px 的内边距。

预览宽度为 960、768 和 375 px。在小屏幕上,预览区域可横向滚动,不会缩小模拟视口。

Tailwind 导出使用任意属性语法。CSS order 改变视觉顺序,而移动按钮改变文档顺序。请注意阅读顺序和键盘导航顺序。

内容对齐仅影响多行弹性布局。单行布局使用项目对齐。

格式参考资料

工具页面更新日期: