垂直居中对齐div中的文本 [英] verticaly center align the text in a div

查看:57
本文介绍了垂直居中对齐div中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为"product-name"的div,高度为30px&11px font-size,它假定包含产品名称.如果产品名称为双行,则看起来不错,但如果产品名称为单行,则从图层的顶部开始,我实际上希望它成为垂直居中对齐.

I have a div named "product-name" with 30px height & 11px font-size, It suppose to contain the product name. If a product name is dual line it seems fine but if the product name is single line it starts from the top of the layer, I actually want it become vertically center align.

请让我知道是否有任何CSS属性或技巧

please let me know if there is any css property or trick

推荐答案

示例: http://jsfiddle.net/JGGQg/

这是我使用的一个技巧:

Here's a trick i've used:

display: table-cell; 
vertical-align: middle;

这篇关于垂直居中对齐div中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆