Centering - Post ID 7602

User 486377 Photo


Registered User
4 posts

I am trying to center the all pages of a site and all contents so that it will be centered for all browsers. Could someone share the code that can be used to do this?
User 233902 Photo


Registered User
1 post

Found this some time ago (can't remenber the author :-()
Place a div id="content" in the body, and this in your css file:

#content{
margin-top: 0px;
margin-left: -350px;
position: absolute;
left: 50%;
width: 700px; //page width
height: 100%;
visibility: visible;
}

Hope I understood your question :-)

Steen, Denmark
User 355448 Photo


Ambassador
3,144 posts

rwhitehouse,

You may want to click on profile and change your forum name to something other than your email address, just to reduce potential spam.

What I would do is something that looks like this (I copied from Cary in a recent post):

<style type="text/css">
body {
text-align:center;
}
#wrapper {
text-align:left; /* to change content back to normal left alignment */
margin:0 auto; /* top and bottom margins of "0". Left and right margins are equal. */
width:990px; /* Auto left and right margins don't work unless you specify the element's width. */
position:relative; /* This is needed so absolutely positioned elements move with the rest of the page as the left and right margins grow or shrink. */
}
</style>

You can adjust the width to suit your needs, but I tend to try setting the width to 760px so that an 800px width monitor does not need to scroll left and right.
User 364143 Photo


Guest
5,410 posts

A way to center using CSS.

#container{
margin:0px auto;
}
CoffeeCup... Yeah, they are the best!
User 2733 Photo


Ambassador
426 posts


Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.