在绝对定位的div中居中文本 [英] center text in an absolute positioned div
本文介绍了在绝对定位的div中居中文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下几种:
I have the following
<div class="label"
style="position: absolute; top: 20px; left: 20px; width: 200px; height: 40px;">
Label Text
</div>
<div class="label"
style="position: absolute; top: 70px; left: 20px; width: 200px; height: 120px;">
Also several lines of
Label Text
may be included
</div>
如何垂直对齐div.label中的文字(可能有多行)?
How can I vertically align the (possibly several lines of) text inside a div.label?
如果需要,我可以添加innerHTML,但不能更改容器(class =label)。
I can add innerHTML if necessary but I can't change the container (class="label").
http://jsfiddle.net/austinfrance/CDTk2/ (现在的工作示例)
推荐答案
您可以使用
You can use something along the lines of
<div class="label"
style="position: absolute; top: 70px; left: 20px; width: 200px; height: 120px; display: table; vertical-align: middle; border:1px solid #000">
<span style="display: table-cell;vertical-align: middle;">
Also several lines of
Label Text
may be included
</span>
请参阅http://jsfiddle.net/99F6D/1/
这篇关于在绝对定位的div中居中文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文