Created
January 17, 2014 17:25
-
-
Save maxxcrawford/8477537 to your computer and use it in GitHub Desktop.
An update to a method found on css-tricks.com to center items within each other without using table positioning. Source: 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
.block:before { | |
border: none; | |
width: 0; | |
} |
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: 99%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment