首页 > 解决方案 > 显示 9x9 div/grid css

问题描述

我正在尝试使用以下 css 制作一个 9x9 div,但如果我显示 4 个 div,如下图所示,它会崩溃

在此处输入图像描述

这是我的CSS

.grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
}
.cell {
  flex: 0 0 33%;
  height: 100px;
  width: 100px;
  margin-bottom: 5px;
}
<div class="grid">
        <div class="cell" style="background-color: green">1</div>
        <div class="cell" style="background-color: red">1</div>
        <div class="cell" style="background-color: blue">1</div>
        <div class="cell" style="background-color: yellow">1</div>
      </div>

我想要的输出是一个 css,它允许我的网格显示以下内容

在此处输入图像描述

标签: htmlcss

解决方案


尝试

justify-content : flex-start;

反而。这使子元素从每行的左侧打包。


推荐阅读