有没有一种简单的方法可以在div中垂直居中?

chr*_*ude 1 html css

我有一个文字<div>,我想垂直居中.任何简单的方法(非绝对定位方法).

Seb*_*lli 7

这是另一种方法:

http://jsfiddle.net/SebastianPataneMasuelli/V2D3L/1/

诀窍是使div的高度与line-height的值相同.

<div>some text</div>

div {
 line-height: 100px;
 height: 100px;   
}
Run Code Online (Sandbox Code Playgroud)

这为您提供了一行垂直居中的文本.

有一种方法:http://www.jakpsatweb.cz/css/css-vertical-center-solution.html.

抱歉,使用绝对定位.

(但它有效)