Forum Moderators: open

Message Too Old, No Replies

Div Tags Left aligning my page

         

CanuckFlorida

8:10 pm on Aug 4, 2006 (gmt 0)

10+ Year Member



I'm new to this so bear with me please.
I put a div tag in my site so that I could have a scrolling box for text. In IE everything is fine, but in Mozilla, the whole page is justified left. What am I doing wrong?

Please help. Thanks

[edited by: encyclo at 9:55 pm (utc) on Aug. 4, 2006]
[edit reason]
[1][edit reason] No personal URLs please, see forum charter [/edit]
[/edit][/1]

Fotiman

9:11 pm on Aug 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to Webmaster World!

Posting URLs is not permitted, and will be deleted by an op. See the TOS [webmasterworld.com].

There are several pretty glaring problems with your pages, including multiple <body> elements. You should validate your html [validator.w3.org] and css [jigsaw.w3.org].

That said, the correct way to center a content block is like so:


<body>
<div id="container">
...
</div>
</body>

In this example, the div with the id of "container" is what we want to make centered and fixed width. Now for the CSS:


body
{
margin: 0;
padding: 0;
text-align: center;
}
#container
{
margin: 0 auto;
width: 767px; /* or whatever fixed width you want */
}

Note, the key is this line:
margin: 0 auto;

That means a top and bottom margin of 0, and a left and right margin of auto.

Regards!