CSS Flexbox:左边的中心容器

这个问题在这里已经有了答案:

  • 弹性框:将最后一行与网格22的答案对齐
  • 在最后一行定位弹性项目3个答案

  • 使用margin-right: auto; 在你的最后一个项目(使用:last-child )上添加一个边框,将你的方框推向左边:

    .container {
      padding: 1em;
      display: flex;
      overflow: auto;
      flex-wrap: wrap;
      min-width: calc(300px + 6em);
      max-width: calc(400px + 8em);
      align-items: center;
      justify-content: center;
      background: red;
    }
    .box {
      width: 100px;
      height: 100px;
      background: #000;
      margin: 1em;
      display: block;
    }
    
    .box:last-child { margin-right: auto; }
    <h1> try resizing window</h1>
    <div class="container">
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
      <div class="box"></div>
    </div>

    我使用Chrome的“Inspect”功能将justify-content改为“flex-start”。

    这似乎产生了你想要的结果。

    在这里输入图像描述

    链接地址: http://www.djcxy.com/p/76051.html

    上一篇: CSS Flexbox: Center container with left

    下一篇: Align items to left, and container to center