我有以下内容
<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 中的(可能是几行)文本?
如有必要,我可以添加 innerHTML,但我无法更改容器 (class="label")。
http://jsfiddle.net/austinfrance/CDTk2/ (现在的工作示例)
最佳答案
你可以使用类似
的东西 <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>
关于html - 在绝对定位的 div 中居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11690828/