CSS Vertical align text to the middle of image

Possible Duplicate:
How do I vertically align text next to an image with CSS?

I have difficulties to center spans vertically middle in div.

This simple code: http://jsfiddle.net/4hDTb/

HTML:

<div class="bar">
    <span>Simple text</span>
    <img src="" class="img1" />
    <span>Another text</span>
    <img src="" class="img2" />
</div>​

CSS:

.bar
{
    width: 100%;
    height: 50px;
    border: 1px black solid;
}
.img1
{
    width: 100px;
    height: 50px;
    border: 1px black solid;
}

.img2
{
    width: 200px;
    height: 50px;
    border: 1px black solid;

}

How to center <span>s in div.bar vertically middle?


just add img{vertical-align:middle} . it's the image you would want to align, not the text.


如果你知道容器的高度 - 你可以使用line-height http://jsfiddle.net/4hDTb/3/检查小提琴..

链接地址: http://www.djcxy.com/p/41520.html

上一篇: 将文字与图像对齐

下一篇: CSS垂直对齐图像中间的文本