minii — 2012-10-19T14:04:49-04:00 — #1
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:
maujor — 2012-10-19T22:32:27-04:00 — #2
briangarcia — 2012-10-19T23:06:59-04:00 — #3
Try using text-align: center ? It should auto center within the content box.
ralphm — 2012-10-20T02:11:52-04:00 — #4
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).
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.
coder911 — 2012-10-23T06:03:24-04:00 — #5
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
system — 2014-10-07T23:05:56-04:00 — #6
This topic is now closed. New replies are no longer allowed.