Last active
August 29, 2015 14:09
-
-
Save croosen/784f08792d93c449ae48 to your computer and use it in GitHub Desktop.
Vertical align with CSS / including Sass mixin
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 align | |
* Use this mixin or placeholder to vertical align elements | |
* @corinneroosen | |
*/ | |
// Mixin | |
@mixin vertical-align { | |
position: relative; // Sometimes you need to try "absolute" here | |
top: 50%; | |
-webkit-transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
transform: translateY(-50%); | |
} | |
.parent .element { | |
@include vertical-align; | |
} | |
// Placeholder | |
%vertical-align { | |
position: relative; | |
top: 50%; | |
-webkit-transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
transform: translateY(-50%); | |
} | |
.parent .element { | |
@extend %vertical-align; | |
} | |
/* CSS for the parent element | |
* In order to prevent blur and other strange behaviour | |
* set a preserve-3d to the parent | |
*/ | |
.parent { | |
-webkit-transform-style: preserve-3d; | |
-moz-transform-style: preserve-3d; | |
transform-style: preserve-3d; | |
} | |
.element { | |
position: relative; | |
top: 50%; | |
transform: translateY(-50%); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment