Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main>
  <h1>Fighting the Flying Footer</h1>
  <section>
    <p>Using <strong>CSS Grid</strong> to position the footer at the bottom - allowing for a variable footer height.</p>
    <hr>
    <h2>Join the Fight!</h2>
    <p>Read the blog post:<br> <a href="https://redonion.se/en/fighting-the-flying-footer/" title="Read the blog post">redonion.se</a></p>
  </section>
</main>

<footer>
  <p>I'm the footer. And I'm happy where I am.</p>
</footer>

              
            
!

CSS

              
                /*Layout styles*/
body{
  display:grid;
  grid-template-columns: 1fr;
  grid-template-rows:1fr auto;
  min-height:100vh;
}

//main{
  /*use margin 0 to have the element take up all space down to the footer*/
  /*margin:0 0 auto 0; /*use margin-bottom auto if you don't want the element to cover the length of the body*/  
//}

footer{
  margin:0;
}

//----------------------------------------------
/*Cosmetic styles*/
:root{
    --modular1: 1.125;
    --modular2: 1.414;

    --startwidth: 30;
    --endwidth:105;

    //need these numbers for h6 and p without units for calc.
    --base-min: 1;
    --base-max:1.25;

    --h1-responsive: calc(var(--h1-size) + ((var(--modular2) * var(--modular2) * var(--modular2) * var(--modular2) * var(--modular2)) - (var(--modular1) * var(--modular1) * var(--modular1) * var(--modular1) * var(--modular1))) * ((100vw - (var(--startwidth) * 1em)) / (var(--endwidth) - var(--startwidth))));
  
      --h2-responsive:calc(var(--h2-size) + ((var(--modular2) * var(--modular2)) - (var(--modular1) * var(--modular1))) * ((100vw - (var(--startwidth) * 1em)) / (var(--endwidth) - var(--startwidth))));  
  
    --p-responsive:calc(var(--p-size) + ((var(--base-max)) - (var(--base-min))) * ((100vw - (var(--startwidth) * 1em)) / (var(--endwidth) - var(--startwidth))));

    --h1-size: calc(var(--modular1) * var(--modular1) * var(--modular1) * var(--modular1) * var(--modular1) * 1em);
  
    //--h2-size: calc(var(--modular1) * var(--modular1) * var(--modular1) * var(--modular1) * 1em);
    --h2-size: calc(var(--modular1) * var(--modular1) * 1em);

    --p-size:calc(var(--base-min) * 1em);
}

body{
  background-color:green;
  text-align:center;
  font-family:/*ios*/ "HelveticaNeue", /*android*/ "Roboto", /*fallbacks*/ Arial, Verdana, "Trebuchet MS", sans-serif;
  color:#584d4d;
}

main{
  background-color:#fffaf8;
  padding:3em 1em 0 1em;
  box-sizing:border-box;
}

footer{
  background-color:aliceblue;
  padding:0 1em;
  box-sizing:border-box;
  background-image:linear-gradient(to right, #ff885d 0%,#ff5062 100%);
  color:#FFF;
}

h1{
  font-family: 'Great Vibes', Arial, Helvetica, sans-serif;
  background-image:linear-gradient(to right, #ff885d 0%,#ff5062 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: rgba(0, 0, 0, 0);  
  color:#2f2f2f;
  font-size: var(--h1-size);
  line-height: 1.45669;//42px;
  margin:(12/28.8325)+em 0;
}

h2{
   font-size: var(--h2-size);
   line-height: 1.629629629629; //33
   margin:(9/20.25)+em 0;
   letter-spacing: 3px;
   text-transform: uppercase;
}

p{ 
  line-height:1.5;
  margin: 0.75em auto;
  font-size:var(--p-size);
}

a{
  color: #FFF;
  background-image:linear-gradient(to right, #ff7644 0%, #f94456 100%);
  text-decoration:none;
  padding:0 0.25em;
  opacity:0.85;
  transition:0.5s opacity;
  display:inline-block;
  margin:0.5em auto 0;
  
  &:hover, &:focus, &:active{
    opacity:1;
  }
}

hr{
  width:5em;
  margin:3em auto;
}

@media only screen and (min-width: 30em) {
  h1, h2{
    //expression for responsive margins
    --margin-responsive: calc((var(--margin-min, 1) * 1rem) + (var(--margin-max, 1.125) - var(--margin-min, 1)) * ((100vw - (var(--startwidth) * 1rem)) / (var(--endwidth) - var(--startwidth))));
    margin:var(--margin-responsive) auto;

    //expression for responsive line-heights
    --lineheight-responsive:calc((var(--lineheight-min) * 1rem) + (var(--lineheight-max) - var(--lineheight-min)) * ((100vw - (var(--startwidth) * 1rem)) / (var(--endwidth) - var(--startwidth))));
    line-height: var(--lineheight-responsive);
  }

  h1{
    --margin-min:0.75; //12
    --margin-max: 1.875; //30;
    --lineheight-min:2.625; //42
    --lineheight-max:7.03125;//112.5
    font-size:var(--h1-responsive);
  }
  
  h2{
    font-size:var(--h2-responsive);
    --margin-min:0.5625;//9
    --margin-max:0.9375;// 15
    --lineheight-min: 2.0625;//33px
    --lineheight-max: 3.28125;//52.5
  }
  
  p{
    font-size: var(--p-responsive);
  }
}

@media only screen and (min-width: 105em) {
  :root{
    //changing scales and base
    --modular1: var(--modular2);
    --base-min: var(--base-max);
  }
  
  h1{
    font-size: var(--h1-size);
    line-height: (112.5/90.4413);
    margin: 0.331706864em auto;//30px
  }
  
  h2{
    font-size: var(--h2-size);
    line-height:(52.5/31.9903);
    margin:(15/31.9903)+em auto;
  }
  
  p{
    font-size: var(--p-size);
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console