views:

404

answers:

2

I have a table based layout which is 100% height/width with no scrollbars. The header (red) automatically expands to fit the content and I don't know how many pixels it will be. The fluid table below gives exactly what I what.

<html>
<body height=100%>
<table height=100% width=100% padding=0>
<tr height=1><td colspan=2 bgcolor=red>Fit<br/>to<br/>content<br/>height</td></tr>
<tr><td bgcolor=blue width=66% valign=top>How can I do this with CSS?</td><td bgcolor=green valign=top>
<div style="height:100%; width:100%; overflow:auto;">
This area can have content that overflows - needs an independent scrollbar.<br/>
0<br/>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>
0<br/>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>
0<br/>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>
0<br/>1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>
</div>
</td></tr>
</table>
</body>
</html>

How can I do the same layout in CSS and have it work on commonly used browsers?

+1  A: 

The header shouldn't be too difficult, for the two columns, I think you'll need to use faux columns to make the colours stretch all the way to the bottom.

For the header I think you'll just want:

HTML:

<div id="header">Fit<br/>to<br/>content<br/>height</div>

CSS:

#header {
    background-color: red;
    width: 100%;
}

p.s. You just made my eyes bleed ;)

Dominic Rodger
This looks like it answers the question I asked but I'm not sure it will exactly fit my needs. I'll test it and either accept this as the answer or refine the question. Thanks.
Andrew
A: 
<html>
<head>
<style type="text/css">
#wrapper
{
 height: 100%;
 width: 100%;
 padding: 0;
}

#header
{
 float: left;
 width: 100%;
 background-color: red;
}

#main
{
 height: 100%;
 width: 100%;
 float: left;
}

#main-left
{
    height: 100%;
 float: left;
 width: 66%;
 background-color: blue;
}
#main-right
{
    height: 100%;
 float: left;
 width: 34%;
 background-color: green;
}
</style>
</head>
<body>

<div id="wrapper">

 <div id="header">
  Fit<br />to<br />content<br />height
 </div> 

<div id="main">

  <div id="main-left">
    How can I do this with CSS?
   </div>

   <div id="main-right">
    Tested in Chrome 2 and IE8
   </div>

 </div>

</div>
</body>
</html>
usoban
I tried this solution in IE8 and Chrome2. Both browsers yield a scrollbar on the right. There should be no scrollbar on the right or at the bottom.
Andrew
I'm pretty sure that's going to cause problems if the content ever exceeds the browser's viewable region, where the colour will not continue all the way to the end of the content.
Dominic Rodger
I've added some content that is too big in the sample to show how I would like it to work where there is a content overflow problem.
Andrew