title: How to make footer stay at bottom of the page with flex-box
body: <p>On iOS Safari when I create a div is a flex item and also make it a flex container, its height does not stretch to match its contents. However if it is not made a flex container then its height does stretch to match its contents.</p>
  
  <p>To elaborate - I am using css flexbox to place a footer at the bottom of the page. The page body has two divs - "maincontents" and "footer". Even if the "maincontents" div has little or no content, the footer will still stay at the bottom of the window. And if the "maincontents" div has a lot of content, it can push the footer down as required. This idea was easily implemented in flexbox by making the page body a flex container, and setting "maincontents" to "flex:1" and "footer" to "flex:0", so that way "maincontents" takes up all available space while "footer" gets pushed to the bottom of the window. It works well on all modern browsers including iOS safari.</p>
  
  <p>The problem arises if I also make "maincontents" a flexbox itself (using display:flex). On iOS Safari the footer now always stays at the bottom of the window, even if maincontents has a lot of content that should push the footer down further; instead "maincontents" ends up continuing underneath "footer" rather than pushing it down.</p>
  
  <p>I have made a barebones mockup of this on jsfiddle. 
  <a href="https://jsfiddle.net/8xs1rocu/" rel="nofollow noreferrer">https://jsfiddle.net/8xs1rocu/</a></p>
  
  <p>Here is what you would see if you open that fiddle on a window desktop (chrome/ff/ie11)
  <a href="https://i.stack.imgur.com/0TfSh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0TfSh.png" alt="enter image description here"></a></p>
  
  <p>And here is what you would see if you open it on an ipad or iphone (safari).
  <a href="https://i.stack.imgur.com/rx0LQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rx0LQ.png" alt="enter image description here"></a></p>
  
  <p><strong>Notice that on iOS safari the footer does not get pushed down by the content, and the content instead ends up going under it</strong>. This does NOT happen on Chrome/FF/IE11 on a desktop; on those browsers the footer is pushed down by the contents of "maincontents".</p>
  
  <p>If you remove the "display:flex" line, then it works perfectly on ios safari too, just as it does on other browsers. However I need that "display:flex" line because I will be putting other content inside "maincontents" that needs to be laid out a certain way using css flexbox.</p>
  
  <p>Pasting the jsfiddle snippet code directly here:</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%;
    display: flex;
    flex-direction: column;
  }
  
  .maincontents {
    flex: 1;
    display: flex; /* if you remove this line it works on Safari */
  }
  
  .footer {
    flex: 0;
    background-color: green;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
    &lt;head&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;div class="maincontents"&gt;
        Main contents1 &lt;br /&gt;
        Main contents2 &lt;br /&gt;
        Main contents3 &lt;br /&gt;
        Main contents4 &lt;br /&gt;
        Main contents5 &lt;br /&gt; 
        Main contents6 &lt;br /&gt;
        Main contents7 &lt;br /&gt;
        Main contents8 &lt;br /&gt;
        Main contents9 &lt;br /&gt;
        Main contents10 &lt;br /&gt;
        Main contents11 &lt;br /&gt;
        Main contents12 &lt;br /&gt;
      &lt;/div&gt;
     
      &lt;div class="footer"&gt;
        Footer1 &lt;br /&gt;
        Footer2 &lt;br /&gt;
        Footer3 &lt;br /&gt;
        Footer4 &lt;br /&gt;
        Footer5 &lt;br /&gt;
        Footer6 &lt;br /&gt;
        Footer7 &lt;br /&gt;
      &lt;/div&gt; 
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>