Forum Moderators: not2easy
Set up your container div class something like this.
.ctr {
position: relative;
margin-left: -50%;
left: 50%;
width: 50ems;
}
The effect of this is to push the left edge of the box to the exact middle of the page (left=50%), then pull it back by half the width off the container (-50%); thus exactly centering the box (div.ctr).
Setting the box size in ems works with any browser font size setting, and every browser (I Believe).
Thanks for the message, but I didn't see it till today. Responses need to be via the forum reply, or other readers will never get to see the response.
You said
Hi, you posted to my question about center a div, but I dont understand. ....If you could contact me on AIM at....
Put whatever you want to center in a box (DIV) and set its width and position. Like this:
<style type="text/css">
div.container {
width: 800px;
position: relative;
top: 20px;
Then center the left edge of the container on the page -
left: 50%;
Next, move the container left by half its own width -
margin-left: -50%; // or in this case, 400px.
}
</style>
The effect is to move the left edge of the container back by half its own width from the page center, thus exactly centering the page, no matter what width the screen is.
Next put your content in the div -
<div class="container">
Your nicely centered content entered in here
</div>
This is a proven cross browser method of centering page content.
Here is a shorthand way that only works with the newer browsers.
div.container {
margin-left; 20px auto;
}