Welcome to WebmasterWorld Guest from

Forum Moderators: not2easy

Message Too Old, No Replies

Centering using text-align



1:35 am on Sep 7, 2009 (gmt 0)

10+ Year Member

How do I center a single div block using text-align: center? I need it for IE5. I can't get it to work putting it on "body".
I've read it here many times.
What's on the page is a lone DIV width 500px.

(margin: 0 auto on the div works fine)


3:22 am on Sep 7, 2009 (gmt 0)

10+ Year Member

I'm guessing text-align: center doesn't work in later browsers. Margin: 0 auto on the div is necessary?


3:46 am on Sep 7, 2009 (gmt 0)

WebmasterWorld Senior Member swa66 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The standard way to center horizontally is auto margins and a given width on block element such as a div.

IE5: that's so ancient it might indeed need what IE6 needs in quirks mode: text-align: center on the parent. I've long since no more copy of IE5 (nor visitors still using it) ...

A standards compliant browser should not center a block if it's parent has text-align:center (that's only for centering inline elements)


Featured Threads

Hot Threads This Week

Hot Threads This Month