简体   繁体   English

简单div内的垂直对齐

[英]Vertical alignment inside a simple div

This is a very simple question, but after a few hours surfing the web I've realized that probably I'm not getting the concept. 这是一个非常简单的问题,但是经过几个小时的网上冲浪后,我意识到我可能没有理解这个概念。

I have: 我有:

<style>
 #more{width:190px; height:44px; border:1px solid #CCCCCC; padding-bottom:3px;vertical-align:middle;}
</style>

 <div id='more'> My text </div>

This does not center the "My text" vertically. 这不会使“我的文本”垂直居中。 How can I center the text vertically? 如何将文字垂直居中?

Thanks a million 太感谢了

You need to use display: table-cell; 您需要使用display: table-cell; to be able to center the text vertically. 才能使文本垂直居中。

Jsfiddle demo. Jsfiddle演示。

I would use line-height equal to the height of your div. 我将使用line-height等于您的div的高度。

line-height: 44px;

NB: this will only work on text in a single line. 注意:这仅适用于单行文本。

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

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