开发者

Vertical alignment inside a simple div

开发者 https://www.devze.com 2023-02-17 22:16 出处:网络
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.

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开发者_如何学C "My text" vertically. How can I center the text vertically?

Thanks a million


I would use line-height equal to the height of your div.

line-height: 44px;

NB: this will only work on text in a single line.


You need to use display: table-cell; to be able to center the text vertically.

Jsfiddle demo.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号