简体   繁体   English

如何垂直对齐我的图像和文本

[英]How to vertical align my images and texts

I am trying to do a vertical align for my texts and images. 我正在尝试对我的文本和图像进行垂直对齐。

It seems the texts are aligned to top in my jsfiddle 看来文字在我的jsfiddle中居高不下

text here      --
              |  |
               --

I want to have my text to be like 我想让我的文字像

               --
text here     |  |
               --

http://jsfiddle.net/wjPxS/ http://jsfiddle.net/wjPxS/

I can't really change my image float right in css. 我真的不能真正更改我的图像浮动在CSS中。 Can anyone help me about it? 有人可以帮我吗? Thanks so much! 非常感谢!

Seeing as you know the height of your container you can just set the line-height the same as height to vertically align the text. 看到你知道你的容器的高度,你可以只设置line-height一样height垂直对齐文本。

Demo 演示

.div1 {
    height: 20px;
    line-height:20px;
}

updated jsFiddle 更新了jsFiddle

You need to apply 你需要申请

display: inline-block;
vertical-align: middle;

to both img and span . imgspan In jsfiddle I replaced span with `div'. 在jsfiddle中,我将span替换为`div'。

Though, this doesn't let you float the img to the right. 但是,这不能让img向右浮动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM