views:

502

answers:

2

I have a header

<h1>My Header</h1>

It has a height of 150px and a font-size of say 1.3em; How can I make the header text vertically centered with CSS. I would rather not wrap it in a container DIV (wrapping divs really defeat the whole CSS idea).

+3  A: 

If the height of the title is 150px, could you also set the line-height to 150px?

h1
{
    font-size: 1.3em;
    line-height: 150px;
    height: 150px;
}
Phil Jenkins
Thanks for the answer. As alexmeia noted it seems the height is unncessary as the line-height already stretches the tag.
borisCallens
+3  A: 

The best way is to add this rule:

h1 {
    line-height: 150px;
}

You don't need to set the height value, and the font size doesn't affect the vertical align.

alexmeia
The font size does affect .. the font size though ;)
borisCallens
Won't this be a problem if the text ends up being multiple lines long?
Travis