Forum Moderators: open

Message Too Old, No Replies

I need help please

web site centering in any browser

         

mitsuman5

10:50 pm on Nov 18, 2007 (gmt 0)

10+ Year Member



My websites are not centered in any browser, i have a laptop and some of the content is off center and on my desktop it is centered. i am using dreamweaver mx 2004 and when i put the content in dreamweaver it is all centered.. Thanks for any help you can give... mitsuman5

Xapti

12:18 am on Nov 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To center an element, you should set a specific width, and use "margin: 0 auto" for the style. In IE6 you'll need to use a workaround by setting the element's parent (the body) to text-align:center, and then in the actual element itself, return the text-align to whatever you wanted.
I really recommend NOT using a WYSIWYG website creator like Dreamweaver, unless you have an adept understanding of HTML and CSS already. The reason being, is you won't learn many important things of web design, or how to do some very basic things. The things you do learn while using it may be messy and improper coding.

Fotiman

5:06 pm on Nov 19, 2007 (gmt 0)

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



This is quite easy to do. First, create your HTML:

<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 {
text-align: center; /* Fix for IE */
}
#container {
margin: 0 auto; /* Center the page */
width: 770px;
/* The border is only to show that it is centered */
border: 1px solid red;
}