将文本居中在div中

Ari*_*ule 3 html css

我试图将文本(水平和垂直)居中,我对此有点困难.

这是我试过的,但只是水平居中,而不是垂直居中.

如何在中心获取此文本?

<div class="playerDetailsPage">
            <p>
                <h4>The text will be in the center</h4>
            </p>

        </div>
Run Code Online (Sandbox Code Playgroud)

CSS

    .playerDetailsPage {
    background-color: #edd4d4; 
    width: 630px;
    height: 390px;
    text-align: center; 
    vertical-align: middle;
    line-height: 390px;
}
Run Code Online (Sandbox Code Playgroud)

Siy*_*yah 6

不要将表格用于此类事情.这不是你可以通过使用表来解决的问题.

对于我所看到的,它是完美的.这是一个工作示例:http://jsfiddle.net/T7V58/1/

你的代码是正确的,有什么问题?只需删除p标签就可以了.

<div class="playerDetailsPage">
           <h4>The text will be in the center</h4>
    </div>
Run Code Online (Sandbox Code Playgroud)

CSS:

   .playerDetailsPage {
    background-color: #edd4d4; 
    width: 630px;
    height: 390px;
    text-align: center; 
    vertical-align: middle;
    line-height: 390px;
}
Run Code Online (Sandbox Code Playgroud)