问题
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:
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 ;)
回答2:
<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>
来源:https://stackoverflow.com/questions/1211331/how-can-i-convert-this-table-based-layout-to-css