Search code examples
htmlcssheaderstylesheet

Center a H2 inside a div element


I want to center h2 inside #top but vertical-align:middle doesn't work... I have no idea what to do!

#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;
}

effect is - http://puu.sh/2mz5M


Solution

  • I see, you have height defined for div, which is great for this situation. You can do this:

    #top h2{
        text-shadow: 2px 2px black;
        text-align: center;
        color: white;
        font-family:"Impact";
        font-size: 50px;
        line-height: 100px;
    }