views:

40

answers:

2

Ahhh Internet Explorer. I've been banging my head against the wall for a couple of hours, and thought it might be time to ask the internets.

When putting someones old javascript function on my page it makes it no longer center in IE(7). What I think is causing it is the page width is getting superficially longer as a result of the script.

This is how I have it centered:

#container{width:960px; margin:0 auto;}

Here is what I have tried to fix it (needless to say it didnt work):

 if (navigator.appName.indexOf("Microsoft")!=-1) {
  document.getElementByID("container").style.marginLeft=(((document.body.offsetWidth - 960)/2));
 }

The page: http://www.roughgiraffed.com/barrandbarrbags/press.html

Thank you ahead of time! :-)

+1  A: 

Internet explorer has had problems with margin:0 auto since the dawn of its creation. Its very picky.

Take a look at number 6 on this article and try that

http://www.webcredible.co.uk/user-friendly-resources/css/internet-explorer.shtml

Ascherer
The "bug" occures on IE9 too, it's his scripts which mess up the layout (have you seen the scrollbars ?!)
MatTheCat
Actually, it's just the missing DOCTYPE that's causing the OP's problem.
Alohci
The missing DOCTYPE must be why this is the only page in the site with this problem. I removed it because it was breaking that awful JS I have to use. body {text-align:center} did however work! Thank you for the article.
Zach Lysobey
@MatTheCat good eye! i think I can remove the scrollbar, just havent looked into it yet.
Zach Lysobey
didnt even look at the doctype, good catch. Always something to look for when IE is acting weird. Its notorious for being stupid with doctype irregularities
Ascherer
I am curious to know how a doctype was breaking JS tho
Ascherer
+1  A: 

Totally agree with the posts above, had a lot of problems with IE before specifying a DOCTYPE, e.g.: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;

Simon Catlin
Why not just <!DOCTYPE html> ?
Šime Vidas
b/c I am not using any features of html5? And all the other pages are xhtml.
Zach Lysobey