Submit a Site

 


Centering the page using CSS

October 2nd, 2007 | by valiik |

Here is how you center a page using CSS. Create a DIV named container that holds the page. Using CSS you set a left padding of 50% which moves the entire page to the right 50% of the screen and aligns?the left edge of the page to the center. Now you just set the left margin to negative half of the container’s size, which in this case is -380 because the container size is 760px. Bam! You have a centered page.

<style>#container {

LEFT: 50%;
MARGIN-LEFT: -380px;
WIDTH: 760px;
POSITION: absolute;

}

</style>

Post a Comment