Skip to content

Instantly share code, notes, and snippets.

@kyrose
Last active August 19, 2019 20:35
Show Gist options
  • Save kyrose/3f83a252fa72218ff35720c278614db5 to your computer and use it in GitHub Desktop.
Save kyrose/3f83a252fa72218ff35720c278614db5 to your computer and use it in GitHub Desktop.
[Sticky footer in two ways] Sticky footers are meant to stick to the bottom of a browser window, unless there is enough content to push the footer lower. #css #flexbox #grid #html
html, body {
height: 100%;
}
body {
display: flex;
flex-direction: column;
}
.content {
flex: 1 0 auto;
}
.footer {
flex-shrink: 0;
html {
height: 100%;
}
body {
min-height: 100%;
display: grid;
grid-template-rows: 1fr auto;
}
.footer {
grid-row-start: 2;
grid-row-end: 3;
}
<body>
<div class="content">
content
</div>
<footer class="footer"></footer>
</body>

Notes

Flexbox

  • use flex: 1 on the child you want to grow to fill the space

or

  • margin-top: auto to push the child away as far as it will go from the neighbor

Grid

Is less widely supported. Should work in Chrome Canary and Firefox Dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment