tags:

views:

68

answers:

4

I have the following HTML.

<body>

<div class="header"></div>

<div class="navdiv"></div>

<div class="mainarea">

<p></p>
<table>
  <tr>
    <th scope="row">Name</th>
    <th scope="row">Description</th>
    <th scope="row">Created</th>
    <th scope="row">Created By</th>
    <th scope="row">Modified</th>
    <th scope="row">Modified By</th>
  </tr>
</table>

</div>

</body>

I need some help with the CSS to structure the page correctly.

I want the header to be 100% across the top which I can do.

But I want the "navdiv" to be a fixed 250px on the left of the page. Then with the "mainarea" div taking the rest of the page to the right of the navdiv. I then also want the table to stretch across the rest of the page.

I have tried several variations and some work however I can't get the table to stretch across the rest of the space, it just either jumps below the nav, goes too far past the other content or only sizes to the content within it.

Can anyone help?

Thanks!

A: 

Have a go with something like this, (untested)

#header{
  width: 100%;
}
#navdiv{
  width: 250px;
  float: left;
}
#mainarea{
  width: 100%;
  float:left;
  margin-left: 260px;
}
table{
  width: 100%;
  float: left;
  clear: left;
}
DavidYell
Hi david, thanks for the reply, I gave your sample a go, but the mainarea div goes below the navdiv, and the table goes to far to the right of the page and adds a scroll...
daviemanchester
+1  A: 

This should work:

.header { width: 100%; }
.navdiv { width: 250px; float: left; height: 400px; background-color: #F00; }
.mainarea { overflow: hidden; position: relative; border: solid 1px #000; }
.mainarea table { width: 100%; border: solid #F00 1px; }
/** hacks for IE6 **/
* html .mainarea { margin-left: 260px; }
* html .mainarea table { float: right; clear: none;  }

Explanation:

I'm essentially using the standard two-column overflow: hidden trick to force the main content to stay in its own column (as opposed to wrapping under the nav). position: relative on the main content is to set it as the table's offset parent, so we can use width: 100% on the table to push it to the width of the main area.

The height on the nav, the background color, and borders are for demonstration purposes only.

On the hacks:

No other (modern) browser requires margin-left: 260px, as that is covered by the overflow: hidden (forcing it into two columns).

Still, at that point, the table seems to clear to the bottom of the nav (again, only in IE6). This is solved by removing any default clear (not sure that's necessary), and floating it to the right, so it doesn't take into account the size of the nav.

Ryan Kinal
@Ryan... I like that you included the hacks for IE 6. Mind explaining the reasoning behind them?
Hristo
Updated with explanations
Ryan Kinal
@Ryan... +1 Thanks!
Hristo
Thanks Ryan thats worked!! Really appreciate it, was driving me mad.
daviemanchester
Always glad to help!
Ryan Kinal
A: 

You can use the following code. I wrapped your code with another div with class wrapper. You can modify the values. The navdiv class has 250px as you wish. You have to modify mainarea's width with percent. This is according to wrapper width. Just play a little and you will find what is the correct percent to fit with the wrapper's width.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>stackoverflow code</title>
<style>

.wrapper {
    width:900px;
    height:400px;
}

.header {
    width:900px;
    height:100px;
}

.navdiv {
    width:250px;
    float:left;
    height:100px;
}

.mainarea {
    width:72%;
    float:left;
    height:100px;
}

</style>
</head>

<body>
<div class="wrapper">
<div class="header"></div>

<div class="navdiv"></div>

<div class="mainarea">

<p></p>
<table>
  <tr>
    <th scope="row">Name</th>
    <th scope="row">Description</th>
    <th scope="row">Created</th>
    <th scope="row">Created By</th>
    <th scope="row">Modified</th>
    <th scope="row">Modified By</th>
  </tr>
</table>

</div>
</div>
</body>

</html>
Sotiris
A: 

Try this: ?

.header{
  width:100%;
  overflow:hidden;
  }

.navdiv{
  width:250px;
  float:left;
  clear:none;
  margin:0 10px 0 0;
  }

.mainarea{
  float:left;
  clear:none;
  overflow:hidden;
  }

.mainarea table{
  width:100%;
  float:left;
  clear:none;
  }
webfac