Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centering text vertically in a header tag 1

Status
Not open for further replies.

TStriker

Programmer
Nov 12, 2003
277
US
This is a simple question but how does a CSS rookie like me vertically center text in an h1 tag?

<h1 style="height: 200px; background-color: red;">Hello World!</h1>

The text is always at the top.

-Striker
 
Centering vertically is very elusive in CSS. You can try to use the line-height property and set it to the height of the containing element. But this only works for a single line of text.

There are other far more complex ways of accomplishing it, but very few work reliably across all browsers.

This page here offers lots of methods

Also if you use an image you can use the vertical_align property on it, but only if its an image.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Line height did it for me since it is only one single line of text. Thanks for the tip!

-Striker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top