title: how to restrict horizontal strech of css flex
body: <p>I am having a <code>div</code> with 3 child <code>div</code>s. I am using CSS flex for dynamically set the height of <code>div</code>. With 3 divs it's working fine.</p>
  
  <p>But there may be a scenario where I will be having 2 child <code>div</code>s. Here child <code>div</code>s are stretching and taking full width of the page. How can I restrict this stretch using only CSS. Check its behaviour by removing <code>div</code> 3.</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>html, body {
      height: 100%;
  }
  
  body {
      margin: 0;
  }
  
  .flex-container .row {
      display: flex;
  }
  
  .flex-item {
      flex: 1;
      display: inline-block;
      background: yellow;
      margin: 10px;
      height: 100px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="flex-container"&gt;
      &lt;div class="row"&gt; 
          &lt;div class="flex-item"&gt;DIV 1&lt;/div&gt;
          &lt;div class="flex-item"&gt;DIV 2&lt;/div&gt;
          &lt;div class="flex-item"&gt;DIV 3&lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>2 child <code>div</code>s streching like this </p>
  
  <p><a href="https://i.stack.imgur.com/vabMm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vabMm.png" alt="2 divs stretching taking entire width"></a></p>