Last active
August 29, 2015 14:24
-
-
Save zaemiel/c3b608b871a56525d6c0 to your computer and use it in GitHub Desktop.
CSS vertical align of text block within div
This file contains 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
**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