I have a very simple holding page I built centering a div, anchor and image. For some reason it will not center in IE8 (either mode), and I am hoping someone can tell me why. I haven't had a chance to try it in other IE browsers. I have tried this in Chrome and FF3 where it works OK.
<html>
<head>
<title>Welcome</title>
<style>
#pageContainer {width:300px;margin:0 auto;text-align:center;}
#toLogo{border:none; }
</style>
</head>
<body>
<div id="pageContainer">
<a href="http://portal.thesit.com" id="toSite"><img src="LOGO_DNNsmall.png" id="toLogo"></a>
</div>
</body>
</html>
I said it was really simple. :)
Thank you,
Brett
You probably want to change it to the following:
The
text-align:center;
is moved to the body. If you want to place other aligned left content within the div#pageContainer
, then you'll needtext-align:left;
for that class. This is the solution that I have used in quite a few websites now and seems to work across all browsers (it's what Dreamweaver uses in it's starter templates).This works for me on IE6,7,8,FF 3.6.3:
and
Do you really want your page to work in quirks mode? Your HTML centers fine once I added doctype to to force standards mode:
Add
text-align:center
to the body. That should do it when combined with themargin:0 auto
on the div.You can center without using the
text-align:center
on the body by wrapping the entire page contents in a full-width container & then settingtext-align:center
on that as well.(I added the
container
div). It doesn't really change anything though... just an extra div. You still need all the same css properties.FOR BLUEPRINT USERS This drove my nuts, until i found this post: problem with ie8 and blueprint Long story short, in you html code change the
for
Regards Alex
The margin of
auto
on the sides of the div leave it up to the browser to decide where it goes. There is nothing telling the browser that the div should be centered in the body, or left or right aligned. So it's up to the browser. If you add a directive to the body, your problem will be solved.I added a 1px border to the div so that you could see what was happening more clearly.
You're leaving it up to the browser because it's in quirks mode. To remove quirks mode, add a doctype definition to the top, like so:
Now you'll be able to see your 300 px div center on the page.