Reputation: 18363
I have a logo with some text. I want the text to be vertically aligned to the middle.
<a class="navbar-brand" href="foo"><img src="bar"/>FooBar</a>
navbar-brand
is defined in Bootstrap like that:
.navbar-brand {
float: left;
height: 50px;
padding: 15px 15px;
font-size: 18px;
line-height: 20px;
}
I've tried wrapping image together with text in span and set its style as follows:
vertical-align: middle;
display: inline-block;
Could someone give me a hint, how should I center the text vertically?
Upvotes: 5
Views: 8665
Reputation: 728
If cross browser compatibility is a must for older browsers the display table approach might be worth looking at. Really liking the answer from Ketan though.
All that would be required is an additional tag around the text like so:
HTML:
<span id="foo">
<img src="http://radiofair.eu/downloads/images/foobar.png"/>
<span>FooBar</span>
</span>
CSS:
#foo{
display: table;
color: red;
}
#foo span{
display:table-cell;
vertical-align:middle;
}
Upvotes: 1
Reputation: 19341
Use following css:
#foo {
align-items: center;
display: flex;
}
Use display:flex
instead of display:inline-block
.
Upvotes: 11