1-866-363-5633
www. Expression - Web - Tutorial .com


Expression Web Tutorials:  Learn How to Build Web Sites with CSS & HTML  ~  A Place For Beginners


CSS Tips n Tricks:  How to Center a Div (center a web page) with CSS

 

We can center a static div by specifying two css properties:

1. Specify a Width (in px, em, or %)

2. Set the margins to auto for left and right. 

Example of a Style Declaration that centers a static div:

#container {  width: 900px;   margin: 0 auto; }

  margin: 0 auto;   is the shorthand way to indicate 0px for the top and bottom margin and auto for the left and right margin.

Note:  we cannot center a layer or an absolutely positioned div, only a static div.  A static div is the default state of a div.

 

Back to CSS Tips Main Page

 

Next CSS Tip    next