A Pen by Mohit Aneja on CodePen.
Created
March 2, 2015 17:35
-
-
Save maneja81/f56864e1f544101f2941 to your computer and use it in GitHub Desktop.
Vertical Align with Pure 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="outer"> | |
<p class="vertical-align"> | |
I am aligned vertically.. | |
</p> | |
</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
/* Outer DIV */ | |
body{ | |
margin: 50px; | |
font-family: "PT Sans", "serif"; | |
} | |
.outer{ | |
margin:50px auto; | |
height: 100px; | |
background: #f7f7f7; | |
border:1px solid #ddd; | |
padding: 20px; | |
} | |
/* Vertical align CSS */ | |
.vertical-align { | |
position: relative; | |
top: 50%; | |
-webkit-transform: translateY(-50%); | |
-ms-transform: translateY(-50%); | |
transform: translateY(-50%); | |
} | |
.element p { | |
.vertical-align(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment