Click to See Complete Forum and Search --> : placing webpages in the centre of the window


qwe
06-14-2007, 02:51 PM
I have noticed an increasing number of websites that have their position centred within the browser window. I have looked at their code but am finding it difficult to seperate the code that does this from the rest. Can anyone make this clearer for me?

thanks

Mr Cherry
06-14-2007, 03:04 PM
Make a table for the entire website to sit in, and center that table. That's how I do it.

slavik
06-14-2007, 04:57 PM
<html><body><center>

lots of code here

</center></body></html>

qwe
06-14-2007, 05:09 PM
thanks for the replies. It's been very useful.

eshbach
06-14-2007, 07:24 PM
both of the answers above are incorrect... or at least, bad solutions.

This is how you'll want to do it:



<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Centered Web Page</title>
<style type="text/css">
#centeredContent
{
margin-left: auto;
margin-right: auto;
width: (something);
}
</style>
</head>
<body>
<div id="centeredContent">
This content will appear in the center.
</div>
</body>
</html>




Also, always remember that this document is your best friend: http://www.w3.org/TR/CSS21/