title: How can I make a flexbox constrain image height?
body: <p>CSS Flexbox newbie here. </p>
  
  <p>I'm trying to achieve a layout with</p>
  
  <ul>
  <li>A fixed-height header</li>
  <li>A content area that takes up all available space, and displays an image.</li>
  <li>A fixed-height footer</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/D85VI.png" alt="enter image description here"></p>
  
  <p>I got this working with the following flexbox code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html style="height: 100%;"&gt;
      &lt;body style="height: 100%;"&gt;
    
          &lt;div style="display: flex; flex-direction: column; height: 100%;"&gt;
              &lt;div style="background-color: rgba(255, 0, 0, .1)";&gt;
                  Header
              &lt;/div&gt;
      
              &lt;div style="flex: 1; background-color: gray;"&gt;        
                  content
              &lt;/div&gt;
      
              &lt;div style="background-color: rgba(0, 0, 255, .1)"&gt;
                  Footer
              &lt;/div&gt;
          &lt;/div&gt;  
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This works great. Now I want to display an image inside of the content area. With small images, this works fine:</p>
  
  <pre><code>&lt;!-- Inside the content div... --&gt;
  &lt;img src="..." /&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/MNKYl.png" alt="enter image description here"></p>
  
  <p>However, with large images, <strong>the image overflows its container</strong> :-(</p>
  
  <p><img src="https://i.stack.imgur.com/Goryk.png" alt="enter image description here"></p>
  
  <p>(Notice how the pony is extending past the content area, overlapping the footer, and beyond.)</p>
  
  <p>I've tried setting <em>max-height: 100%</em> on the img, but it still overflows the container. How can I fix this?</p>