title: How can I have a sticky footer with my CSS Grid layout?
body: <p>I found <a href="https://codepen.io/chriscoyier/pen/YWKNrE" rel="noreferrer">this CodePen solution</a> for a sticky footer in a CSS Grid layout, but it has two problems for me:  </p>
  
  <ol>
  <li>It is kinda ugly with <code>min-height: 100%</code> and <code>height: 100%</code></li>
  <li>It only works with two elements in the body (a div and a footer)</li>
  </ol>
  
  <p>I need something that works with this HTML structure:</p>
  
  <pre><code>&lt;body&gt;
      &lt;nav&gt;Some navigation buttons&lt;/nav&gt;
      &lt;main&gt;The content&lt;/main&gt;
      &lt;footer&gt;Copyrights and stuff&lt;/footer&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I don't really want to pack the <code>&lt;nav&gt;</code> and the <code>&lt;main&gt;</code> into a <code>&lt;div&gt;</code>, and I would love to do this in pure CSS.</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-js lang-js prettyprint-override"><code>// Not required!
  // This is just to demo functionality.
  
  $("#add").on("click", function() {
    $("&lt;p&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.&lt;/p&gt;").appendTo(".content");
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>html {
    height: 100%;
  }
  
  body {
    min-height: 100%;
    display: grid;
    grid-template-rows: 1fr auto;
  }
  
  .content {
    padding: 20px;
  }
  
  .footer {
    grid-row-start: 2;
    grid-row-end: 3;
  }
  
  * {
    box-sizing: border-box;
  }
  
  body {
    margin: 0;
    font: 16px Sans-Serif;
  }
  
  h1 {
    margin: 0 0 20px 0;
  }
  
  p {
    margin: 0 0 20px 0;
  }
  
  .footer {
    background: #42A5F5;
    color: white;
    padding: 20px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="content"&gt;
    &lt;h1&gt;Sticky Footer with Grid&lt;/h1&gt;
    &lt;p&gt;&lt;button id="add"&gt;Add Content&lt;/button&gt;&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;footer class="footer"&gt;
    Footer
  &lt;/footer&gt;</code></pre>
  </div>
  </div>
  </p>