Related resources
Other articles
- Center a web page in CSS »
- Basics of Database optimisation »
- How to configure Outlook Express to receive emails »
- How to configure Outlook 2007 to receive emails »
- HTML Base Tag »
- Scaleable HTML and CSS Guide, Part 1 - Introduction »
- Problems Encountered With PHP DOM Functions »
- Refactoring code with find, xargs and sed »
- What do webdesigners need from clients »
- Using any font on a website »
One simple way to center a web page using CSS is to create a container div, that is horizontally centered by having its left and right margins set to auto.
Using this method, you can still apply colours / background images to the body tag, so its a flexible solution. (if you didnt need this ability, just apply margins and width to the body tag instead, and forget using the container div).
The container div has the same width as your webpage and, well, contains it. All the code for your web page is placed inside the container div.
This will work fine in any current standards compatible browser. It also works in Internet Explorer versions 5 and up (but good luck in getting any half complicated site working properly in IE5...).
This solution is very simple to implement, and requires only a few lines of code.
The HTML
The CSS
Good luck with your own coding! This simple example will be enough to get you started.
We've made this available for download. Download center-web-page.zip







Comments
There are no comments for this post