Last active
December 30, 2015 04:39
-
-
Save gabrieljoelc/7777185 to your computer and use it in GitHub Desktop.
Pretty solid way to center vertically with HTML/CSS. From http://css-tricks.com/centering-in-the-unknown/
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
.something-semantic { | |
display: table; | |
width: 100%; | |
} | |
.something-else-semantic { | |
display: table-cell; | |
text-align: center; | |
vertical-align: middle; | |
} |
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="something-semantic"> | |
<div class="something-else-semantic"> | |
Unknown stuff to be centered. | |
</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
/* This parent can be any width and height */ | |
.block { | |
text-align: center; | |
} | |
/* The ghost, nudged to maintain perfect centering */ | |
.block:before { | |
content: ''; | |
display: inline-block; | |
height: 100%; | |
vertical-align: middle; | |
margin-right: -0.25em; /* Adjusts for spacing */ | |
} | |
/* The element to be centered, can | |
also be of any width and height */ | |
.centered { | |
display: inline-block; | |
vertical-align: middle; | |
width: 300px; | |
} |
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="block" style="height: 300px;"> | |
<div class="centered"> | |
<h1>Some text</h1> | |
<p>But he stole up to us again, and suddenly clapping his hand on my shoulder, said—"Did ye see anything looking like men going towards that ship a while ago?"</p> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment