Skip to content

Instantly share code, notes, and snippets.

@fnky
Created April 5, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnky/827c6d18d8fab3e414f81933a0c6f9f1 to your computer and use it in GitHub Desktop.
Save fnky/827c6d18d8fab3e414f81933a0c6f9f1 to your computer and use it in GitHub Desktop.
Dynamic Vertical Alignment in CSS
/*
Flexbox method
Supported in most browsers, including legacy ones like IE8 and IE9
https://caniuse.com/#feat=flexbox
*/
html, body {
height: 100%;
height: auto;
}
body {
margin: 0;
padding: 0;
}
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
}
/*
Display Table method
Supported in most browsers, including legacy ones like IE8 and IE9
https://caniuse.com/#feat=css-table
*/
html, body {
height: 100%;
height: auto;
}
body {
margin: 0;
padding: 0;
}
.container {
display: table;
height: 100%;
width: 100%;
}
.container__content {
display: table-cell;
vertical-align: middle;
height: 100%;
width: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment