2011-02-10 169 views
15

好吧,这里就是这个HTML元素看起来像现在:垂直居中对齐文本

enter image description here

我想文字与图像的中心。图像是32x32px。

这里是我的代码:

<style> 
div.interface { 
    line-height: 32px; 
    float: left; 
    margin: 10px; 
    width: 450px; 
    font: 14px/27px 'CalibriRegular', Arial, sans-serif; 
    color: #646464; text-shadow: 1px 1px 1px #fff; 
    padding-right: 10px; 
} 
</style> 

<div class="interface"><img src="assets/icons/interface.png" />Filled with fun animations and eye-candy! Complete with Retina graphics.</div> 
+1

检查这个问题出:HTTP ://stackoverflow.com/questions/4414034/how-to-vertically-align-elements-in-html/4414069#4414069 – JCOC611 2011-02-10 03:05:10

+0

@JCOC:看起来只是我需要的东西。对不起,我没有足够的搜索。不妨在这里复制你的答案,这样我就可以接受答案。 :) – 2011-02-10 03:07:57

+0

Nah,没关系!我已复制粘贴我的答案,并编辑了一下,以适应更多的情况! – JCOC611 2011-02-10 03:10:47

回答

32

要居中文本垂直设置的行高到相同的高度,例如:

img{ height: 30px; } 
#text{ line-height: 30px; } 

和垂直取向设置为中间:

#text{ line-height: 30px; vertical-align:middle; }