CSS Centering div
I want to simply center text on a page...
I started doing this by creating a div, and then setting the width to a specific number and applying auto left/right margins.
However, all it is is text. So when changing the width, the centering changes. It doesn't appear to be center anyway, just relatively center.
My other problem is I'd like to have it centered vertically as well. How would I achieve this?
This is specifically what I'm trying to center:
Try using text-align: center ? It should auto center within the content box.
Hi Minii. Welcome to the forums. :)
Yes, you are only centering the box there, not the text. (If you but a background color n the div you will see that it is centered ... unless some other CSS is interfering with the positioning).
Originally Posted by Minii
If you want each line of text centered, do what Brian suggested. Vertical centering is a little harder. Let us know if Maujor's link doesn't help.
width: 800px; margin: 0 auto can be used to center align block elements (width is required, won't work otherwise). To center the text contents inside an element, use text-align: center