Created
May 21, 2014 07:28
-
-
Save MiguelDebruyne/44cf0bba7aa6b12594f7 to your computer and use it in GitHub Desktop.
CSS: Vertical Center Unknown Child (with pseudo el)
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment