Cannot centre page in internet explorer 6

Hi

I have used the following code and the page will not centre in IE 6. Does anyone know whats wrong ? Thanks in advance

CSS :

body
{
	background-color: #7c2983;
	color: #fff;
	font-family: helvetica, arial, sans-serif;
	font-size:62.5%;
	margin: 0; 
	padding: 0;
	text-align: center;  /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
	width: 100%;
}
#container
{
	width: 1024px;
	margin: 34px auto;
	text-align: left;
	
}

#header h1 
{
	color: #7c2983;
	background: url(../images/touchstone_logo.gif) no-repeat top left;
	font-size: 1.6em;
	margin: 0;
	padding: 10px 0px 20px 0px;
	text-indent: -400px;
	display: block; /* this hides the indented touchstone communications text */
}

h1 
{
	display: inline;
	font-size: 11.5em;
	line-height: 0.85em;
	margin: 0 0 0px -6px;
	padding: 0px;
}

p
{
	font-size: 1.5em;
	line-height: 1.4em;
	text-align: justify;
	}

/* re-usable classes */

.bold {
	font-weight: bold;
}

.image_float_left
{
	float: left;
	margin-right: 20px;
}

.left 
{
float:left;
margin: 0 70px 0 0;
}

a {
	color: #fff;
	text-decoration: none;
	font-weight: bold;
}

/* removes dotted border on links in nav */
a:focus 
{
	outline: 0px;
} 

a.nonbold 
{
	font-weight: normal;
}

a.pink 
{
	color: #e9cbed;
	clear: both;
	font-size: 1.5em;
	font-weight: bold;
	text-decoration: none;
	float: left;
	margin-left: 524px;
}	

a:hover 
{
	color: #FFFFFF;
}
	
/* navigation */
#navigation
{
	float: left;
	width: 1024px;
	padding: 0px;
	margin: 0px;
	
}

#navigation ul
{
	list-style-type: none;
	margin: 0px 0px 0px -10px;
	padding: 0px;
}

#navigation ul li
{
	
	display: inline;
	margin: 0px;
	padding: 0px;
}

#navigation li a
{
	border-right : 1px solid #e9cbed;
	color: #e9cbed;
	display: block;
	font-size: 1.5em;
	float: left;
	margin: 24px 0px 41px 0px;
	padding: 0px 10px 0px 10px;
	text-decoration: none;
	font-weight: normal;	
}

/* turns off seprator (vertical line)  border on right side of last tab in navigation */
#navigation ul li a.page_nav_last {border-right-style: none;}

#navigation a:hover, body#index #t-index a, body#barbara #t-barbara a, body#tracy #t-tracy a, body#work #t-work a, body#expertise #t-expertise a, body#services #t-services a, body#contact #t-contact a
{
	color: #fff;
}

#content
{
	float: left;
	width: 1024px;
	margin-top: 30px;
}

#content ul 
{
	margin-left: -10px;
}

#content li
{
	font-size: 1.5em;
	margin: 0;
	padding: 0;
	font-weight: normal;
	line-height: 1.6em;
}

#main 
{
	float: left;
	width: 500px;
}

#aside
{
	float: right;
	margin-top: 0px;
	margin-left:24px;
	margin-right:50px;
	padding-top: 0;
	width: 450px;
}

#aside a
{
	display: block;
	position: relative;
	top: 65px;
}

/* expertise and services */

#expertise #content div, #services #content div
{
	margin-right: 100px;
}

/* contact */

#contact_details #address 
{
	clear: both;
	float: left;
}

#footer
{
	clear: both;
	font-size: 1.5em;
	height: 1%;
	text-align: left;
	padding: 40px 0 0 0;
}

#footer ul
{
	margin: 0px;
	padding: 0px;
	list-style-type: none;
}

#footer ul li
{
	display: inline;
	margin: 0 10px 0 0;
	padding: 0px;
}

It would be good to post your HTML too, as we need to see what these styles are applying to, as that may be the problem. Presumably everything goes inside the container, but we don’t know without the HTML. Preferably post a link.

What about other versions of IE, do they center the page?

From looking at your CSS the #container div should be centering just fine.

You might have IE in quirks mode due to missing or malformed doctype.

We would need to see the html that goes with your CSS before we can help any further. :slight_smile:

Edit: Whoops, Ralph just mentioned the html too


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Meet Barbara - Touchstone Communications</title>
<style type="text/css">
@import url(css/styles.css);
</style>
<link rel="shortcut icon" href="/favicon.ico" />
</head>

<body id="barbara">
<div id="container">
	<div id="header">
		<h1>
			Meet Barbara - Touchstone Communications
	  </h1>
	</div>
	<div id="navigation">
		<ul>
			<li id="t-index"><a href="index.html">Home</a></li> 
<li id="t-barbara"><a href="barbara.html">Meet Barbara</a></li>
			<li id="t-tracy"><a href="tracy.html">Meet Tracy</a></li>
			<li id="t-work"><a href="work.html">How We Work</a></li>
          <li id="t-expertise"><a href="expertise.html">Our Expertise</a></li>
          <li id="t-services"><a href="services.html">Our Services</a></li>
          <li id="t-contact"><a href="contact.html" class="page_nav page_nav_last">Make Contact</a></li>
		</ul>
	</div>
	
	<h1>
				<img src="http://www.sitepoint.com/forums/images/barbara_elliott.jpg" alt="photo of Barbara Elliott" class="image_float_left" />Barbara <br /> Elliott
	  </h1>
<div id="content">

			<div id="main">
			<p>
				I&#8217;m a graduate of the Marketing Institute of Ireland with over twenty years experience in public relations consultancy and in-house, advising and working with clients in almost every sector you can name. 
The scope and variety of what I do is one of the big attractions for me and I relish the challenges that working in public relations brings.</p>
<p>I&#8217;m proud to be a multiple recipient of the Certificate of Excellence at the PRCA Awards for Excellence in Communication for my work in corporate sponsorship, public information and healthcare. 	</p>
	  </div>
		<div id="aside">
			<p>When not working, it&#8217;s all about family and close friends. Inbetween, I devour books, watch a lot of films, practise yoga and can&#8217;t resist local community fundraising quiz nights.  </p>
     </div>
     <div><a href="tracy.html" class="pink">Meet Tracy</a></div>
       </div><!--ends content -->
     <div id="footer">
        <ul>
        <li>Touchstone Communications</li>
        <li>+123456789</li>
        <li><a href="mailto:me@example.com">me@example.com</a></li>
        </ul>
	  </div>
          <!--ends footer -->     
</div><!--ends container -->
    

</body>
</html>

I tested your code in IE6 and it centered fine. Only difference was that I didn’t use @import but just pasted the CSS inside the <style> tags. Maybe try a standard stylesheet link and see it that helps.

I also wouldn’t use that outermost div of 100% width. You can just as well put those styles on the <body> element.

Ralph

Thanks very much for your help - very much appreciated

One quick question : as I have 100% set on the body in the css, why would I need to place it in the html <body> tag.

Would it be better to change 100% to 1024px on the body in the css ?

Thanks again for taking the time to respond - nice one !

Duh, I’m a twit. I thought those styles on the <body> were actually for an other div. (Or, to put it another way, I thought you havd a div of width: 100% around the container. Didn’t look carefully enough.) Just remove the width setting on the body altogether, as it’s not needed.

Cheers - thanks for all your help.

Yes - I thought the width declaration was’nt needed.

Good to know my code is clean and it validated fine.

Thanks for all your help

Firstly - thanks for all the responses

I have checked the site (Touchstone Communications - Public Relations) on IE 6 and it is still not centering the page plus the pages where i have 2 lists side by side they are overlapping.

I have checked the doc type declarations and validated the pages via w3c website - does anyone know what might be the problem

Thx

HI,

The page is centering in IE6 ok but is a little out due to the double margin-bug on the floated #aside. Add display:inline to fix the bug (see faq on floats for more info).


#aside {
    float: right;
    margin-top: 0px;
   /* margin-left:24px; not needed */
    margin-right:50px;
    padding-top: 0;
    width: 450px;
    display:inline;
}

As the element next to #aside is floated left then you don’t need the margin-left:24px on #aside as it is redundant and eats up any breathing space that you might have had for errors.

The list overlaps because you have given it a 10px margin which … err… makes it overlap :slight_smile:

Remove the negative margin here:


#content ul {
    /*margin-left: -10px;*/
}


Thanks very much Paul O’B - I will check it out - your time is much appreciated

Hi all

From the previous replies it seems that yes the page is centered in IE 6 however on my IE 6 it is aligning left. Please see screenshot attached. Is this just my IE6 ?

Thanks all for the help !!!

(IE 6 please die)

You probably need to refresh your page or clear your cache. It’s defiantly centered in IE6. :slight_smile:

ok thanks guys - good to kinow i am not losing my mind or eyesight - big thx all around

It definitely is :slight_smile:

ok I cleared cache and refreshed and also checked on another machine that never had visited the site and still left aligned- thx for all the replies - don’t know whats going on - think i will leave it at that

@import? What is this, 1998?

LINK, with a media type.

Of course here your code doesn’t work in ANY browser… and just leaves me with a bunch of questions… Like:

  1. Is this a NEW site? If so, what’s with the Tranny doctype? Transitional is for supporting old/outdated/half-assed coding techniques, NOT for building new websites.

  2. what’s with all the endless DIV for nothing. You’ve got perfectly good semantic block-level containers like H1 and UL, what do you need the extra div like #header and #navigation around them for?

  3. much less the ID on the body.

  4. and the content cloaked H1

  5. and the multiple H1’s…

  6. and the list around unrelated items in the footer.

  7. comment placement that could trigger IE rendering errors.

… and some sensible formatting wouldn’t hurt either.

I’m guessing wildly here, but I suspect that the markup for that should look a little more like this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
	xmlns="http://www.w3.org/1999/xhtml"
	lang="en"
	xml:lang="en"
><head>

<meta
	http-equiv="Content-Type"
	content="text/html; charset=utf-8"
/>

<meta
	http-equiv="Content-Language"
	content="en"
/>

<link
	type="text/css"
	rel="stylesheet"
	href="screen.css"
	media="screen,projection,tv"
/>

<link
	rel="shortcut icon"
	href="/favicon.ico"
/>

<title>
	Meet Barbara - Touchstone Communications
</title>

</head><body>

<div id="pageWrapper">

	<h1>
		<img
			src="http://www.sitepoint.com/forums/images/barbara_elliott.jpg"
			alt="photo of Barbara Elliott"
		/>
		Barbara<br />
		Elliott
	</h1>

	<ul id="mainMenu">
		<li><a href="index.html">Home</a></li>
		<li><a href="barbara.html">Meet Barbara</a></li>
		<li><a href="tracy.html">Meet Tracy</a></li>
		<li><a href="work.html">How We Work</a></li>
		<li><a href="expertise.html">Our Expertise</a></li>
		<li><a href="services.html">Our Services</a></li>
		<li><a href="contact.html">Make Contact</a></li>
	</ul>

	<div id="content">

		<div class="subSection">
			<p>
				I&#8217;m a graduate of the Marketing Institute of Ireland with over twenty years experience in public relations consultancy and in-house, advising and working with clients in almost every sector you can name. The scope and variety of what I do is one of the big attractions for me and I relish the challenges that working in public relations brings.
			</p><p>
				I&#8217;m proud to be a multiple recipient of the Certificate of Excellence at the PRCA Awards for Excellence in Communication for my work in corporate sponsorship, public information and healthcare.
			</p>
		<!-- .subSection --></div>

		<div class="subSection odd">
			<p>
				When not working, it&#8217;s all about family and close friends. Inbetween, I devour books, watch a lot of films, practise yoga and can&#8217;t resist local community fundraising quiz nights.
			</p>
		<!-- .subSection.odd --></div>

		<a href="tracy.html" class="meet">Meet Tracy</a>

	<!-- .content --></div>

	<div id="footer">
		Touchstone Communications
		<span>+123456789</span>
		<a href="mailto:me@example.com">me@example.com</a>
	<!-- #footer --></div>

<!-- #pageWrapper --></div>

</body></html>

I’d have to see a live page with all the images in place to say for sure though. The CSS once I got it to apply (using LINK) still isn’t telling me a whole lot – well, apart from the broken image replacement technique on the first H1 (that probably is so presentational it shouldn’t even be in the markup – either that or the second h1 shouldn’t even be a heading), the use of that broken “62.5%=10px” nonsense (which isn’t even true on my computer!), a fixed width that’s not even 1024 friendly, reliance on default line-heights which is why all the content lines are overlapping each-other here, and presentational classes like ‘nonbold’ and ‘pink’ missing the point of using CSS in the first place.

Apart from the extra errors Deathshadow has mentioned above you don’t seem to have used the code I gave you earlier so the page is still off-center in ie6 with the double margin bug pushing the container wider and thus the layout looks off-center