CSS centering content on page

Posted 19 April, 2009 in Other Stuff

center divCentering your content on a page using CSS is not complicated once you know how:

  1. You need to create a content or container div that all the content goes into.
  2. In your css you need to give the content container a width and then set the left and right margins to auto.

Example HTML:

<body>
 <div id=”content”>
  <!– Content goes here –>
 </div>
</body> 

Example CSS:

#content {
  margin-left: auto;
  margin-right: auto;
  width: 500px;
 }

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • StumbleUpon
  • Twitter
  • Yahoo! Buzz

Your comment: