views:

216

answers:

4

I'm having a problem with a centered div only on IE7... on Chrome and Firefox it works properly.

Here is the website, it's on Volusion.com so go easy on me it's an old platform :)

http://www.ecosandbags.com

Everything is in a main div:

<div id="MainDiv">

Here is the CSS

#MainDiv {
background-color:White;
border:1px solid black;
margin:0 auto;
width:960px;
}

Anyways check it out with FireBug in Firefox if you need to see more details but that should be it...

So, bottom line, the div is centered on Chrome and Firefox but all the way to the right on IE7... I'm not sure what to do this CSS (specifically the "margin: 0 auto;" usually works for me)

Thank you very much for your time.

A: 

Try:

#MainDiv {
position:relative;
background-color:White;
border:1px solid black;
margin:0 auto;
width:960px;
}
Nick
Adding position relative will not help.
David Dorward
+1  A: 

I've had this issue before - this has always been a reliable solution for me;

body{
   text-align:center;
}

#MainDiv {
   text-align:left;
   margin:0 auto;
   background-color:White;
   border:1px solid black;
   width:960px;
}
na_user
This is a relatively ugly hack, and there is no need for it unless you need to support IE5.5 and earlier. See answers about Quirks mode.
David Dorward
+4  A: 

You're in Quirks Mode. Add a Standards Mode DOCTYPE if you want auto margins (or anything much) to work in IE.

bobince
bobince has hit the nail on the head here.
Jason Leveille
Bobince,Thank you for your reply, that definitely fixed the problem! :) I used the code sample from Rochal below to fix.
Robert
+1  A: 

You are missing doctype.

Add this as a very first line of your html document and it will solve the problem:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

Funny, I was asked to help with exactly same issue in the office yesterday.

rochal
Better to use HTML (XHTML + HTML Compatibility is more work, and few people benefit from it) and Strict (since Transitional is pretty much Strict + Bad Practices).
David Dorward
Thank you for your reply, that fixed it!
Robert