title: Maintain aspect ratio of div containing image in flexbox
body: <p>I have some images divided up into two rows with widths that grow and shrink with the container as the browser window is resized.</p>
  
  <p>However, the images can be any aspect ratio, and I have to constrain them to an 80 width : 53 height ratio. I've been trying all sorts of things for almost a day now to no avail. How am I supposed to achieve 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>body {
    background-color: #666;
    display: flex;
    justify-content: center;
  }
  
  .container {
    background-color: white;
    display: flex;
    flex-wrap: wrap;
    width: 90%;
  }
  
  .img-box {
    flex-basis: 50%;
  }
  
  img {
    display: block;
    width: 100%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Parcel Sandbox&lt;/title&gt;
      &lt;meta charset="UTF-8" /&gt;
      &lt;link rel="stylesheet" href="./src/styles.css" /&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
      &lt;div class="container"&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553155905-b94ab6f10bc8?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553174975-8b6c0a0d8fc9?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553155905-b94ab6f10bc8?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553155905-b94ab6f10bc8?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553174975-8b6c0a0d8fc9?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553155905-b94ab6f10bc8?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553155905-b94ab6f10bc8?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
        &lt;div class="img-box"&gt;
          &lt;img
            src="https://images.unsplash.com/photo-1553155905-b94ab6f10bc8?ixlib=rb-1.2.1&amp;q=80&amp;fm=jpg&amp;crop=entropy&amp;cs=tinysrgb&amp;w=400&amp;fit=max&amp;ixid=eyJhcHBfaWQiOjU1Nzk4fQ"
          /&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;script src="src/index.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The codesandbox: <a href="https://codesandbox.io/s/8x3qjompz9" rel="nofollow noreferrer">https://codesandbox.io/s/8x3qjompz9</a></p>
  
  <p><strong>The ideal result:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/q9uE7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q9uE7.png" alt="enter image description here"></a></p>