Last active
January 4, 2016 08:49
-
-
Save macx/8597572 to your computer and use it in GitHub Desktop.
Vertical aligned elements.
Source: http://zerosixthree.se/vertical-align-anything-with-just-3-lines-of-css/
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
<div class="box"> | |
<div class="box__inner is-vertical-aligned"> | |
VERTICAL ALIGNED | |
</div> | |
</div> |
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
@import "compass"; | |
@import "compass/css3"; | |
// the magic | |
%is-vertical-aligned { | |
@include transform(translateY(-50%)); | |
position: relative; | |
top: 50%; | |
} | |
body { | |
font-family: Helvetica, Arial; | |
background-color: #f5f5f5; | |
} | |
.box { | |
box-shadow: 0 1px 5px rgba(#000, 0.2); | |
margin: 30px auto; | |
width: 200px; | |
height: 200px; | |
padding: 10px; | |
background-color: #fff; | |
.box__inner { | |
@extend %is-vertical-aligned; | |
background-color: #d00; | |
color: #fff; | |
padding: 10px; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment