Vertically align a heading and a paragraph in a div

Posted by davey on Stack Overflow See other posts from Stack Overflow or by davey
Published on 2012-06-21T14:46:16Z Indexed on 2012/06/21 15:16 UTC
Read the original article Hit count: 219

Filed under:
|
|
|

I'm trying to vertically align a h1 element and p in the middle of a div floated left but they end up next to each other vertically aligned. Im pretty sure it to do with the table-cell display but don't know how to vertically align without it.

my code gives me:

.
.
Heading Paragraph
.
.

I want:

.
.
Heading
Paragraph
.
. 

heres my code:

CSS:

#HDRtext 
{
    float:  left;
    width: 30%;
    height: 335px;
    padding: 0;
    display: table;
    color:  white;
}

#HDRtext h1 
{
    font-family: Georgia;
    font-size: 2em;
    display: table-cell;
    vertical-align: middle;
}

#HDRtext p {
    display: table-cell;
    vertical-align: middle;
    font-size:1em;
    font-family: Georgia;
}

© Stack Overflow or respective owner

Related posts about html

Related posts about css