Created
June 4, 2012 08:56
-
-
Save abernier/2867324 to your computer and use it in GitHub Desktop.
CSS vertical centering technique
This file contains 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
.vcenter {white-space:nowrap;} | |
.vcenter > * {white-space:normal;} | |
.vcenter:before, | |
.vcenter >* {display:inline-block; vertical-align:middle;} | |
.vcenter:before {content:""; height:100%;} | |
.vcenter {word-spacing:-.25em;} | |
.vcenter > * {word-spacing:normal;} |
This file contains 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
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<title>Vertical centering CSS technique</title> | |
<link rel="stylesheet" href="index.css"> | |
<div class="vcenter" style="height:100px; border:1px solid;"> | |
<p style="border:1px dotted;">I'm vertically centered.<br>I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered. I'm vertically centered.</p> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bl.ocks.org/abernier/2867324