Created
April 5, 2018 13:10
-
-
Save fnky/827c6d18d8fab3e414f81933a0c6f9f1 to your computer and use it in GitHub Desktop.
Dynamic Vertical Alignment in CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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