Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Vertically centering the text in a div

Vertically centering the text in a div

Problem

I need your help,

How can the text be Vertically centered in my custom alert box.

I thought that by having the existing css properties of:

#alertBox_text {
  width: 100%;
  height: auto;
  text-align: center;
  margin-top: 10px;
}

That it would automatically appear to be centered.






    
IMTS
Problem courtesy of: John Smith

Solution

Text-align only applies to horizontal alignment.

If you wish to Vertically Align text and you know your container's height, you can use the line-height property to vertically align single-line text by setting it equal to the height.

Alternatively, use one of the techniques documented here: http://css-tricks.com/centering-in-the-unknown/

Solution courtesy of: Jimmy Breck-McKye

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

Vertically centering the text in a div

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×