Forum Moderators: not2easy

Message Too Old, No Replies

CSS Centred Layout

         

terrybarnes

6:50 pm on Dec 14, 2007 (gmt 0)

10+ Year Member



Hi, Please forgive me as I am very new to CSS layouts and it's been driving me crazy trying to first of all set it up and then secondly hunt around the web for a similar layout that I could take the code and adapt around my own design.

What I'm trying to do is have a 790px width cell centred in the browser window and have a 10px space at the top and bottom of the browser window. The cell would also have a 30px grey border. Within that cell there would be 3 rows. top (100px fixed) for header, middle (50px fixed) for navigation and bottom section would be the content area and would therefore need to be fluid within the cell so if the user resizes their browser window then the main cell would still remain 10px from top and bottom of browser.

I hope all this makes sense and someone may be able to guide me in the right direction. Thanks in advance for any help.

Xapti

9:51 pm on Dec 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well what you're asking for is very simple. This should be the basis of what you want. Let me say one thing though; I'm curious to know what that center div is for (hence mysterydiv), possibly even the top one. It's very likely you won't need it/them. It's likely you'd want a header tag instead of a div.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>your example</title>
<style type="text/css">

*{margin:0;padding:0} /*this is my preference for universal reset of spacings*/
body{padding:10px 0;text-align:center}/*the two text-align things which appear over these two lines are to fix IE's quirky rendering*/
#main{width:790px;margin:0 auto;border:30px solid gray;text-align:left;background-color:#fc0}/*margin:0 auto; means 0 margin on top and bottom, centered on left-right.*/
#header{height:100px;background-color:#5cd}
#mysterydiv{height:50px;background-color:#ff3}
#content{background-color:#d4a}

</style>
</head>
<body>

<div id="main">
<div id="header">
test
</div>
<div id="mysterydiv">

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

</body>
</html>

terrybarnes

10:20 pm on Dec 14, 2007 (gmt 0)

10+ Year Member



Hi, many thanks for your help with this. The main thing that needs to happen though is the grey border box always needs to span the entire height of the browser window - even if there's only a small amount of content in the "content" div. That's what I always have a major problem with - the issue of filling content to 100% of the browsers height?!