title: Flex: wrapped items with same width as the rest
body: <p>I'm using flex to create a multi column list that adjusts the number of columns based on the width of the container.</p>
  
  <p>The problem I found is that if I want to use the full width of the parent by setting flex-grow to 1, the items in the last wrapped row are misaligned, since they try to fill the parent.</p>
  
  <p>I found two workarounds that don't work for me: one used media queries, which I can't use because the parent is not the same width of the viewport; the other was using <code>columns</code>, but I can't use it because it causes issues with outlines being cut off and wrapped, which I have in my real setup.</p>
  
  <p><a href="https://i.stack.imgur.com/Xb9Je.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xb9Je.png" alt="Last two items&#39; witdth is different"></a></p>
  
  <p><strong>Q:</strong>
  Is there a way to make all items have the same width while filling the parent on full rows?</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>* {
    box-sizing: border-box;
  }
  
  .wrapper {
    border: 1px solid red;
    width: 50%;
  }
  
  ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    margin: -1em -1em 0 0;
  }
  
  li {
    border: 1px solid black;
    padding: 1em;
    margin: 1em 1em 0 0;
    flex: 1 1 10em;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="wrapper"&gt;
    &lt;ul&gt;
      &lt;li&gt;Item 1&lt;/li&gt;
      &lt;li&gt;Item 2&lt;/li&gt;
      &lt;li&gt;Item 3&lt;/li&gt;
      &lt;li&gt;Item 4&lt;/li&gt;
      &lt;li&gt;Item 5&lt;/li&gt;
      &lt;li&gt;Item 6&lt;/li&gt;
      &lt;li&gt;Item 7&lt;/li&gt;
      &lt;li&gt;Item 8&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://plnkr.co/edit/0u2QxcdLkDfhwV3zASrM" rel="nofollow noreferrer">https://plnkr.co/edit/0u2QxcdLkDfhwV3zASrM</a></p>
  
  <p>Resize until you get 2 items in the last row.</p>