Last active
September 5, 2019 22:09
-
-
Save acdha/a91a46706de02c37566a to your computer and use it in GitHub Desktop.
How to vertically center arbitrary contents using flexbox with backwards compatibility for IE10, Safari 5.1, Android < 4.4, etc.
This file contains hidden or 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
.vertical-center { | |
display: -moz-box; | |
-moz-box-align: center; | |
display: -webkit-box; | |
-webkit-box-align: center; | |
display: -ms-flexbox; | |
-ms-flex-align: center; | |
display: -webkit-flex; | |
-webkit-align-items: center; | |
display: flex; | |
align-items: center; | |
} |
This file contains hidden or 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
@mixin vertically-centered-contents { | |
// See http://caniuse.com/#feat=flexbox | |
// 2009 Working Draft: Safari 5.1, Android 4.3 and lower, etc | |
@include flexbox(( | |
display: box, | |
box-align: center, | |
), $version: 1); | |
// March 2012 Working Draft: IE10 | |
@include flexbox(( | |
display: flexbox, | |
flex-align: center, | |
), $version: 2); | |
// Final standard: IE11, Firefox, Chrome, Safari 6+ | |
@include flexbox(( | |
display: flex, | |
align-items: center | |
)); | |
} | |
.vertical-center { | |
@include vertically-centered-contents(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment