Simple Way To Center A DIV On A Page
February 6th, 2008 | by valiik |Here is a simple way to center a DIV on a page using CSS.
Use this:
#myDiv {
margin: 10px auto;
}
10px is the top margin. If you don’t want any margin you can use 1px, but you have to use something, else it won’t work and you will need to use the second method.
Second method:
#myDiv {
position: absolute;
width:750px;
left: 50%;
margin-left: -375px;}
Use absolute positioning.
position: absolute;
Specify the size of your div, in pixels.
width:750px;
Then you position the left edge of the div in the center of the page.
left: 50%;
And now you just moove the DIV to the left half of it’s size, half of 750 in our case is 325.
margin-left: -375px;
And you’re done.





