3 replies [Last post]
CeceV
CeceV's picture
Offline
newbie
New York
Last seen: 18 years 52 weeks ago
New York
Joined: 2003-12-16
Posts: 6
Points: 0

I would like to create and center a web page for 800x600 display in a CSS without any tables.

Can anyone recommend the best method for this without using any onload javascript?

Dan the Man
Offline
newbie
Last seen: 18 years 40 weeks ago
Timezone: GMT+1
Joined: 2004-03-05
Posts: 3
Points: 0

Centering web page with css

Put a div to wrap all content, e.g.:

<div id="wrap">
content
</div>

Then create the style (without my comments):

#wrap {
position: relative;
width: 750px; <----fixed width
height: 430px;
margin: 0px auto; <---- left and right margin is "auto"
}

CeceV
CeceV's picture
Offline
newbie
New York
Last seen: 18 years 52 weeks ago
New York
Joined: 2003-12-16
Posts: 6
Points: 0

Centering web page with css

Thanks, exactly what I needed. Tested and it works beautifully.

josefk
Offline
newbie
london uk
Last seen: 18 years 39 weeks ago
london uk
Joined: 2004-03-09
Posts: 2
Points: 0

Centering web page with css

As far as I know this only works in standards compliant browsers (Mozilla, etc) but not in IE, surprise surprise. But there are other ways, see:

http://bluerobot.com/web/css/center1.html
http://bluerobot.com/web/css/center2.html