Skip to content

Instantly share code, notes, and snippets.

@uniZero
Created May 4, 2013 15:06
Show Gist options
  • Save uniZero/5517745 to your computer and use it in GitHub Desktop.
Save uniZero/5517745 to your computer and use it in GitHub Desktop.
Center an element vertically using a :before pseudo element. (http://stackoverflow.com/a/12686489/1725363)
.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