CSS Vertical align text to the middle of image [duplicate]

喜夏-厌秋 提交于 2019-12-23 08:52:31

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/9348889/css-vertical-align-text-to-the-middle-of-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!