CSS Vertical align text to the middle of image [du

2019-06-17 05:24发布

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?

2条回答
Root(大扎)
2楼-- · 2019-06-17 06:13

if you know the height of the container -- you can use line-height http://jsfiddle.net/4hDTb/3/ check the fiddle..

查看更多
【Aperson】
3楼-- · 2019-06-17 06:23

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

查看更多
登录 后发表回答