473,396 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Margin:auto in IE7

I'm having some issues with the layout of my container div. In firefox 2.0 its working normally, but in IE7 everything is pushed to the left. Here is the website. Ideally the header would stay aligned with the background when the browser windows are resized, but I can't even get them consistent in both browsers.

Any ideas? I'll be happy to post code if needed.
May 30 '07 #1
5 31325
So FYI - I resolved this issue myself. The answer at this website which talks about best practices for webpage development. Here's the part that was helpful...


center

The ancient <CENTER> tag can safely retire, too. CSS is quite capable of centering text and blocks of content, though there's one catch.

To center the text in div.text you do:

div.text {
text-align: center;
}

Centering entire blocks is somewhat trickier. If you want to center the entire div.text, the official CSS way is:

div.text {
margin-left: auto;
margin-right: auto;
}

auto means: “as much as you need.” The <div> takes as much margin as it needs and equally divides it between left and right. As a result it is centered.
Unfortunately the auto value does not work in Explorer for Windows. Instead, you must use text-align on a block containing div.text:

div.container {
text-align: center;
}

div.text {
margin-left: auto;
margin-right: auto;
text-align: left; /* overrule inheritance */
}

<div class="container">
<div class="text">
This entire block is centered
</div>
</div>

This use of text-align is not quite standards-compatible, but it's the only way to make Explorer for Windows behave. And yes, it's one of the very few cases where divitis and classitis are good for your page.
May 30 '07 #2
drhowarddrfine
7,435 Expert 4TB
I don't know how old that link is but "auto" works just fine for centering in IE.
[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<body>
<div style="height:100px;width:100px;background-color:red;margin:auto;">
</div>
</body>
</html>[/HTML]
May 30 '07 #3
Yes, it does work in IE 6+, but ONLY if you do have a DOCTYPE declaration. Almost no one seems to mention this.
Oct 30 '10 #4
drhowarddrfine
7,435 Expert 4TB
The doctype declaration has no effect on whether that works or not but doctypes are required for all new web pages so having one goes without saying.
Oct 31 '10 #5
@HTDuck
THANK YOU VERY MUCH.. Everybody telling something how to do what to do but i didnt realize that i forgot to mention DOCTYPE thing in my site and thats why im not able to center the page.. after seeing this i made it THANK YOU VERY MUCH again. i signed up to this site just to reply you thanks.!
Feb 25 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alex Bell | last post by:
Thanks to the people who helped me with centering a block of text in MSIE 5.5 in the site I am developing at http://www.members.iinet.net.au/~abell1/test/index.htm with city.css at...
5
by: Duane Lambe | last post by:
Hi - just a quick question, I hope it's simple enough that a visual example isn't required. I have an internal site, everything's the way I want it, but there's an anomoly in both Opera and...
4
by: yawnmoth | last post by:
margin-left: auto; margin-right: auto; doesn't seem to be centering tables in a webpage I'm working on, in IE. It does so in Opera, but not in IE. Any ideas as to why? Or better yet, what I can...
22
by: Jim Moe | last post by:
Hello, Is there a way to have a div size itself to the width of its contents? "width:auto" does not work. The div contains a UL and I want the div to fit the longest line in the list. The div is...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
1
by: neridaj | last post by:
Hello, I've found a few postings of this problem but none of the answers seem to fix my problem. I have a content div wrapped around a left floated image and a right floated table. I want the...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
6
by: Jeff | last post by:
Updating my bag of tricks again. What's the level of support for margin: auto. Is this widely supported now amongst almost all browsers? It's a common request to have a "centered" page. I...
1
by: superDk | last post by:
Hello, IE6 is adding a large margin between my two containers (container1 & container2) everything works fine in IE7 and Firefox. I've been searching on-line for a fix but I've had no luck. It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.