centering page in Mozilla\Firefox...

liunx

Guest
I can add the style


body {
text-align: center;
}


to my css and that centers the page in IE, however it doesn't in Mozilla. What else do I need to do to get it to work in MOzilla?

TIAmargin:0 auto; should work for you mate it will work for ie in with a strict doctype i think also so you may not need text-align:center;

Hope that helps.thanks for the help, but that didn't do anything for either IE, or Firefox.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>center contents</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
body {text-align: center}
#alignment {text-align: left; margin: auto auto; width:60%;}
p {background:red;}
-->
</style>

</head>
<body>
<div id="alignment">
<p>contents
</p>
</div>
</body>
</html>I think you made need a width on whats getting centered for my suggestion if it doesnt i have no idea why it doesnt work because it works for me.as fang said, margin: auto will need to be applied to a div around the page content, not the body tag. that's probably the problem ;)Ah now i remember cheers for correcting me dave.isn't there somethign about Opera not supporting 0 Auto?

You have to specifiy the property for each elemenet individually, i.e. margin-left:auto; margin-right:auto;?

DavidThe script I gave works in Opera.i think its something to do with an earlier version of Opera... i must look it up!Ive found its always better to use a container div or other block element to center a page like so:



<div style="text-align: center">
<div style="width: 400px; border: 1px #000000 solid; text-align: left;">
This text will be left justified in this div but the div will be centered
</div>
</div>mseiler look at your code in Firefox.CSS Centering 101 (<!-- m --><a class="postlink" href="http://www.simplebits.com/notebook/2004/09/08/centering.html">http://www.simplebits.com/notebook/2004 ... ering.html</a><!-- m -->)CSS Centering 101, the same code as I gave, although it does explain why.
 
Back
Top