Center an HTML page with CSSPosted on By Addam Driver Sunday, September 25, 2011
Ok… Here is one of the most frustrating things ever. HOW TO CENTER AN HTML PAGE WITH CSS! I use to do this by wrapping the page inside a div and centering that div. It works and it’s solid but if you want to use a true CSS method, check this out.
This will only work if the DOCTYPE is XHTML Transitional or Strict. IT WILL NOT WORK if your doctype is HTML 4.x. Here is an example of what it should look like:
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en”>
Put this at the top of your CSS file and you will be good to go!
** Again this works in ALL BROWSERS including IE6. If you want it to see it in action, just GO TO THIS SITE using different browsers. Cheers!