在div元素中居中H2

Fil*_*uzi 2 html css header stylesheet

我想把h2放在#top中但vertical-align:middle不起作用......我不知道该怎么做!

#top {
    display: block;
    position: relative;
    height: 100px;
    background-color: rgba(89,144,222,.6);
}
#top h2{
    text-shadow: 2px 2px black;
    text-align: center;
    color: white;
    font-family:"Impact";
    font-size: 50px;
}
Run Code Online (Sandbox Code Playgroud)

效果是 - http://puu.sh/2mz5M

小智 5

我知道,你为div定义了高度,这对于这种情况很有用.你可以这样做:

#top h2{
    text-shadow: 2px 2px black;
    text-align: center;
    color: white;
    font-family:"Impact";
    font-size: 50px;
    line-height: 100px;
}
Run Code Online (Sandbox Code Playgroud)