且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

DIV块中的CSS中心文本(水平和垂直)

更新时间:2021-09-06 21:56:06

如果它是一行文本和/或图像,那么很容易做到。只需使用

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.