.top{height:100px;background:gray;}
.main{height:300px;background:red;width:100%;position:relative;}
.left{width:200px;position:absolute;left:0;top:0;height:300px;background:blue;}
.right{background:#9c9;height:300px;margin-left:210px;}
.foot{height:50px;background:#f63;}
.main{height:300px;background:red;width:100%;position:relative;}
.left{width:200px;position:absolute;left:0;top:0;height:300px;background:blue;}
.right{background:#9c9;height:300px;margin-left:210px;}
.foot{height:50px;background:#f63;}
.main{width:500px;height:300px;background:red;margin:0 auto;position:relative;}
.left{width:200px;height:300px;background:blue;float:left;top:0;left:0;}
.right{position:absolute;height:300px;background:green;right:0;width:55%;}
.foot{height:50px;background:orange;clear:both;}
.left{width:200px;height:300px;background:blue;float:left;top:0;left:0;}
.right{position:absolute;height:300px;background:green;right:0;width:55%;}
.foot{height:50px;background:orange;clear:both;}
只需要在.left{}中添加float:left;在.right{}中添加float;right;就可以起到效果。然后如果想有间隙,也即是和效果图一样的话,就必须要修改.left和.right中的width值,使左右相加的值小于960px即可。
.top{width:100%;height:100px;background:#ccc;}
.main{height:800px;background:red;}
.left{width:200px;height:800px;background:blue;position:absolute;}
.right{margin-left:210px;width:100%;height:800px;background:green;position:absolute;}
.foot{width:100%;height:100px;background:orange;margin:0 auto;}
.main{height:800px;background:red;}
.left{width:200px;height:800px;background:blue;position:absolute;}
.right{margin-left:210px;width:100%;height:800px;background:green;position:absolute;}
.foot{width:100%;height:100px;background:orange;margin:0 auto;}
已采纳回答 / 不想去想名字
因为main受到了浮动影响, main里面的left和right都是浮动的,则父元素要清楚浮动才能够不塌陷,可以通过在父元素里加入一个空标签,或者在main的样式里面加入 overflow:auto; 这句来清除浮动,这样就看得到黑色啦!
2016-05-14