Skip to content

Instantly share code, notes, and snippets.

@acdha
Last active September 5, 2019 22:09
Show Gist options
  • Save acdha/a91a46706de02c37566a to your computer and use it in GitHub Desktop.
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.
.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;
}
@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