Skip to content

Instantly share code, notes, and snippets.

@zaemiel
Last active August 29, 2015 14:24
Show Gist options
  • Save zaemiel/c3b608b871a56525d6c0 to your computer and use it in GitHub Desktop.
Save zaemiel/c3b608b871a56525d6c0 to your computer and use it in GitHub Desktop.
CSS vertical align of text block within div
**A.) If you only have one line of text:**
HTML:
<div>vertically centered text</div>
CSS:
div
{
height: 200px;
line-height: 200px; /* <-- this is what you must define */
vertical-align: middle;
}
**B.) If you have multiple lines of text:**
HTML:
<div><span>vertically centered text</span></div>
CSS:
div
{
height: 200px;
line-height: 200px;
}
span
{
display: inline-block;
vertical-align: middle;
line-height: 14px; /* <-- adjust this */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment