title: Scale svgs to same height and fit in 1 row in flexbox
body: <p>I'm trying to create a banner which contains accepted payment icons. I want to scale the images such that they all end up with the same height, where that height is the maximum possible such that the images all fit in one row. The images are not all the same size or aspect ratio (because, for example, they aren't just credit cards, they include the MasterCard ID Check logo).</p>
  <p>I have this working in Safari, but it doesn't work in either Chrome or Firefox (and fails differently).</p>
  <p>Desired outcome (Safari):</p>
  <p><a href="https://i.stack.imgur.com/Dsi4r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dsi4r.png" alt="enter image description here" /></a></p>
  <p>Chrome failure case, all the images fit in the row, not all heights are set the same:</p>
  <p><a href="https://i.stack.imgur.com/aEXrI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aEXrI.png" alt="enter image description here" /></a></p>
  <p>Firefox failure case, all images scaled to same height, but the wrappers overflow the flex container:</p>
  <p><a href="https://i.stack.imgur.com/vLtwn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vLtwn.png" alt="enter image description here" /></a></p>
  <p>Initially, I had just put the <code>&lt;img&gt;</code>s in as the children of the flex container (actually, initially initially, I tried to put all the svgs into an svg view sprite, but that ended up failing in lots of other ways that it was taking me too long to diagnose), but after poking around here a while, it became clear that I needed to wrap them in another set of <code>&lt;div&gt;</code>s, scale those divs (the children of the flex container), and then let the size of the images auto adjust. Most of the examples on here deal with scaling the other direction, but I just swapped the width/height parameters, and thought I was good (Safari is my default browser).</p>
  <p>What's the cross-browser way to get my desired outcome?</p>
  <p>HTML:</p>
  <pre><code>&lt;div class=&quot;payment-icons&quot;&gt;
      &lt;div class=&quot;icon-container&quot;&gt;
          &lt;img class=&quot;icon payment-icon&quot; src=&quot;1.svg&quot;&gt;
      &lt;/div&gt;
      &lt;div&gt;...&lt;/div&gt;
      ...
  &lt;/div&gt;
  </code></pre>
  <p>CSS:</p>
  <pre><code>// flex container
  .payment-icons {
      display: flex;
      justify-content: space-between;
      padding-top: 10px;
      max-width: 281px;
      margin-left: auto;
      margin-right: auto;
  }
  
  // flex items
  .payment-icons .icon-container {
      min-width: auto;
  }
  
  // images
  img { // from an earlier rule; included here in case it matters
      display: block;
      height: auto;
      max-width: 100%;
  }
  
  img.payment-icon {
      height: auto;
      width: 100%;
  }
  </code></pre>
  <p>You can see it working (or not, depending on your browser) in this snippet:</p>
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.payment-icons {
    display: flex;
    justify-content: space-between;
    padding-top: 10px;
    max-width: 281px;
    margin-left: auto;
    margin-right: auto;
  }
  
  .payment-icons .icon-container {
    min-width: auto;
  }
  
  .payment-icons .icon-container:not(:last-child) {
    padding-right: 5px;
  }
  
  img {
    display: block;
    height: auto;
    max-width: 100%;
  }
  
  img.payment-icon {
    height: auto;
    width: 100%;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  
  &lt;body&gt;
    &lt;div class="payment-icons"&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-1-payment-icon-visa" src="https://www.dropbox.com/s/wxk2xjzo52e2p9d/1-payment-icon-visa.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-2-payment-icon-mc" src="https://www.dropbox.com/s/vzev285htn06dmk/2-payment-icon-mc.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-3-payment-icon-amex" src="https://www.dropbox.com/s/eur0beji6qep55p/3-payment-icon-amex.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-4-payment-icon-up" src="https://www.dropbox.com/s/zvni8pygvob2vvi/4-payment-icon-up.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-5-payment-icon-cb" src="https://www.dropbox.com/s/227ujpum81gigsc/5-payment-icon-cb.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-6-payment-icon-visa-secure" src="https://www.dropbox.com/s/p5zr6atbjfac6i5/6-payment-icon-visa-secure.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
      &lt;div class="icon-container"&gt;
        &lt;img class="icon payment-icon payment-icon-7-payment-icon-mc_idcheck" src="https://www.dropbox.com/s/5y26briolgpmko6/7-payment-icon-mc_idcheck.svg?raw=1" aria-hidden="true" focusable="false" role="presentation"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I'd ideally like to solve this with HTML/CSS, but if push comes to shove, I can edit the SVGs. I even tried naively modifying them. The first four items all have height and width set in the <code>&lt;svg&gt;</code> tag, whereas the last three set it inside the first bounding rectangle, and it crossed my mind that that might be the issue. So, e.g., the Visa card:</p>
  <pre><code>&lt;svg width=&quot;750&quot; height=&quot;471&quot; viewBox=&quot;0 0 750 471&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;&gt;
      &lt;path...
  </code></pre>
  <p>whereas the MasterCard ID Check:</p>
  <pre><code>&lt;svg id=&quot;a5689fc5-8d5e-4b19-817c-171f8cabf65a&quot; data-name=&quot;Layer 1&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 504.16287 144&quot;&gt;
      &lt;rect width=&quot;504.16287&quot; height=&quot;144&quot; style=&quot;fill:none&quot;/&gt;
      ...
  </code></pre>
  <p>I tried adding width and height to the Mastercard <code>&lt;svg&gt;</code> in various different combinations, but it seems not to have mattered. As I said, I'd prefer not to monkey with this, but if that's the only way, I can.</p>