首页 > 代码库 > 三栏的网页布局,中间内容不确定高,问怎么让两边的背景始终与内容高度一致

三栏的网页布局,中间内容不确定高,问怎么让两边的背景始终与内容高度一致

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#box{ width:900px;}
#left{ width:300px; background:#699; float:left}
#center{ width:600px;background:#FC3; float:left}
</style>
</head>

<body>
<div id="box">
    <div id="left">111</div>
    <div id="center">
    ccccccccccccc
    <br />
    ccccccccccccc
    <br />
    ccccccccccccc
    <br />
    ccccccccccccc
    <br />
     ccccccccccccc
    <br />
    ccccccccccccc
    <br />
    ccccccccccccc
    <br />
    ccccccccccccc
    <br />
    ccccccccccccc
    <br />
    </div>
</div>
</body>
<script type="text/javascript">
window.onload=function(){
   document.getElementById("left").style.height= document.getElementById("center").offsetHeight+‘px‘;
}

</script>
</html>