title: Center a group of wrapped flex items
body: <p>I'm trying to center a group of wrapped flex items. The HTML looks like this:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>main {
    background-color: blue;
    width: 390px;
    display: flex;
    justify-content: center;
  }
  
  .container {
    background-color: red;
    display: inline-flex;
    flex-wrap: wrap;
  }
  
  .a1 {
    color: grey;
    width: 100px;
    height: 200px;
    background-color: green;
    border: 1px solid black;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;main&gt;
    &lt;div class="container"&gt;
      &lt;div class="a1"&gt;&lt;/div&gt;
      &lt;div class="a1"&gt;&lt;/div&gt;
      &lt;div class="a1"&gt;&lt;/div&gt;
      &lt;div class="a1"&gt;&lt;/div&gt;
    &lt;/div&gt;
  &lt;/main&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://jsfiddle.net/shefwpqr/" rel="noreferrer">DEMO</a></p>
  
  <p>The above looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/YL84N.png" rel="noreferrer"><img src="https://i.stack.imgur.com/YL84N.png" alt="enter image description here"></a></p>
  
  <p>The green boxes are wrapped correctly, but they, as a whole, are not centered in the red area, </p>
  
  <p><a href="https://i.stack.imgur.com/LlxrW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LlxrW.png" alt="enter image description here"></a></p>
  
  <p>without defining a width on the <code>.container</code> because the red block can have any size and I want to fit as many blocks next to each other as possible.</p>
  
  <p>Any suggestions how to center the wrapped green blocks?</p>
  
  <p>UPDATE: According to <a href="https://stackoverflow.com/questions/32802202/how-to-center-a-flex-container-but-left-align-flex-items">this</a> 2 year old post it is not possible. So in my case I have to use javascript to fix this. But maybe I can use <a href="https://css-tricks.com/snippets/css/complete-guide-grid/" rel="noreferrer">CSS Grid Layout</a></p>