Skip to content

Instantly share code, notes, and snippets.

@marceux
Last active August 29, 2015 14:06
Show Gist options
  • Save marceux/01687535dd2cb7631a97 to your computer and use it in GitHub Desktop.
Save marceux/01687535dd2cb7631a97 to your computer and use it in GitHub Desktop.
CSS Vertical Centering
/* This parent can be any width and height */
.block {
// Any Property
}
/* 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment