DIV块中的CSS中心文本(水平和垂直) [英] CSS Center text (Horizontal and Vertical) inside a DIV block
问题描述
我有一个 div
设置为 display:block
。 ( 90px
高度和宽度)和我里面有一些文本。
I have a div
set to display:block
. (90px
height and width) and I have some text inside.
我需要文本在
我尝试了 text-align:center
,但它不会水平部分,所以我尝试 vertical-align:middle
但它不工作。
I have tried text-align:center
, but it doesn't do the horizontal part so I tried vertical-align:middle
but it didn't work.
p>
推荐答案
如果它是一行文本和/或图像,那么很容易做到。只需使用
If it is one line of text and/or image, then it is easy to do. Just use
text-align: center;
vertical-align: middle;
line-height: 90px; /* the same as your div height */
如果它可以是多行,那么它有点更复杂。但有关于 http://pmob.co.uk/ 的解决方案,请查找垂直对齐。
that's it. If it can be multiple lines, then it is somewhat more complicated. But there are solutions on http://pmob.co.uk/ Look for "vertical align".
因为他们往往是黑客或添加复杂的div ...我通常使用一个表与单个单元格做它...使它尽可能简单。
Since they tend to be hacks or adding complicated divs... I usually use a table with a single cell to do it... to make it as simple as possible.
这篇关于DIV块中的CSS中心文本(水平和垂直)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!