title: css3 flexbox limit 4 items per row auto width
body: <p><a href="https://i.stack.imgur.com/UaD6R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UaD6R.png" alt="enter image description here"></a>
  How can I achieve this using flexbox? Currently, I am using table but I wrap every row in a div to limit it to 5 items only. I want all the items wrapped in one parent only.</p>
  
  <p>I tried flexbox but I want the items width depends on its content. Thank you guys.</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>.flexContainer {
    display: flex;
    flex-flow: row wrap;
   }
   .flexContainer .item {
    padding: 5px;
    flex: 1 1 auto;
   }
   .flexContainer .item a {
    display: block;
    background: blue;
    text-align: center;
   }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="flexContainer"&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;sdfsf&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dffdfdf&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;fdfdfd&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;fdfdgdf&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;ffffffffff&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;fdfdfdg&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dddddddddddddd&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;fdfdfdsd&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dsds&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dffdfdfdsf&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dffdfdfsdsds&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dffdfdfssdsfd&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dfsddfdfdf&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dff&lt;/a&gt;&lt;/div&gt;
   &lt;div class="item"&gt;&lt;a href=""&gt;dffdfdfdffdfdfdffdfdf&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>