Tuesday, April 28, 2009

CSS: Center Aligning Text Vertically - Method 2

You can center text vertically by using absolute positioning on the child element and setting the top property to 50%. You might have to adjust the margin-top attribute to get the text exactly in the center.


div#header {
position: relative;
height: 200px;

div#header span {
position: absolute;
top: 50%;
margin-top: -10px;

<div id="header">
<span>My text</span>

No comments:

Post a Comment