Vertically align text within a div [duplicate]
Solution 1:
Andres Ilich has it right. Just in case someone misses his comment...
A.) If you only have one line of text:
div
{
height: 200px;
line-height: 200px; /* <-- this is what you must define */
}
<div>vertically centered text</div>
B.) If you have multiple lines of text:
div
{
height: 200px;
line-height: 200px;
}
span
{
display: inline-block;
vertical-align: middle;
line-height: 18px; /* <-- adjust this */
}
<div><span>vertically centered text vertically centered text vertically centered text vertically centered text vertically centered text vertically centered text vertically centered text vertically centered text vertically centered text vertically centered text</span></div>
Solution 2:
Create a container for your text content, a span
perhaps.
#column-content {
display: inline-block;
}
img {
vertical-align: middle;
}
span {
display: inline-block;
vertical-align: middle;
}
/* for visual purposes */
#column-content {
border: 1px solid red;
position: relative;
}
<div id="column-content">
<img src="http://i.imgur.com/WxW4B.png">
<span><strong>1234</strong>
yet another text content that should be centered vertically</span>
</div>
JSFiddle