flex实现从上到下,从左到右排序

263 阅读1分钟

flex实现从上到下,从左到右排序

正常来说,想要实现从上到下,从左到右排序,很多朋友不会的都跑去使用JS实现,实际上使用Flex布局轻松实现。主要就flex-wrap: wrap,允许换行 和 flex-direction: column,主轴方向切换位Y轴。

.container {
  display: flex;
  flex-wrap: wrap;
  flex-direction: column;
  height300px;
  gap10px;
  border4px solid red;
}

.item {
  display: flex;
  align-items: center;
  justify-content: center;
  width300px;
  height30px;
  color: white;
  font-weight700;
  font-size16px;
  background-colorrgb(19195244);
}