Search code examples
htmlcssinternet-explorer-8quirks-mode

How do I automatically center a div in IE8 in quirksmode?


I am working with IE8 in quirks mode...

I have styles cascading from my Firefox stylesheet which include:

#container {position:relative; width:1007px; margin-right:auto; margin-left:auto;}       

#textbin {width:720px; position:relative; margin-right:auto; margin-left:auto;}

Apparently I'm not doing something right, or auto-margining does not work in IE8. Is this the case? If so, how can I get around this limitation? I tried no positioning, absolute positioning, and even adding relative position to my IE8 stylesheet. Furthermore, when I manually center the div, IE8 adds margin to the bottom of the page...

by the way, I am a beginner here, so if more info is needed please let me know!


Solution

  • The old-school hack-y way to do it was to add text-align:center to the parent of the div you want to center. Of course you'll need to then specifically declare a text-align property for the child elements if you don't want them to be center aligned, as text-align is going to be inherited by child elements.