I want to vertically align a span after a floated image. I searched for it in stack overflow and find this post. but my image is floated.
<div>
<img style="width:30px;height:30px; float:left">
<span style="vertical-align:middle">Doesn't work.</span>
</div>
I give vertical-align:middle
to image and nothing change!
Thanks
First remove
float
from it. Write like this:Check this http://jsfiddle.net/ws3Uf/
A
<span>
is an inline element, try addingdisplay:block
to the span, give it the same height as the image and a line height to match. Float it left as well. That should workYou could do the following:
You can manually change as well
Demo
Or you can use a table
Even though this is an extremely old post, you can achieve this using
Flexbox
:JsFiddle example
Add
line-height
(equal to picture height):See example.