body{ margin:0; padding:0; font-size:30px; color:#fff}
.top{width:100%;background:RGB(204,204,204);height:100px;}
.main{background:red;position:relative;}/*使left以main为基准绝对定位*/
.top{width:100%;background:RGB(204,204,204);height:100px;}
.main{background:red;position:relative;}/*使left以main为基准绝对定位*/
.left{ width:200px;height:500px;background:blue;position:absolute;left:0;top:0;}
.right{height:500px;background:RGB(154,204,153);margin-left:210px;}
.foot{width:100%;background:RGB(255,102,52);}/*因为是position实现排版,所以不需要清除浮动*/
.right{height:500px;background:RGB(154,204,153);margin-left:210px;}
.foot{width:100%;background:RGB(255,102,52);}/*因为是position实现排版,所以不需要清除浮动*/
/*solution 2:calc used*/
.left{float:left; width:200px; height:500px;}
.right{float:right; width:calc(100% - 205px); height:600px;}
.foot{clear:both;}
.left{float:left; width:200px; height:500px;}
.right{float:right; width:calc(100% - 205px); height:600px;}
.foot{clear:both;}
/*solution 1:div.left must shorter than div.right.*/
.top{width:100%;}
.main{position:relative;}
.left{width:200px; position:absolute; left: 0; top: 0; height:510px;}
.right{margin:0px 0px 0px 210px; height:500px;}
.foot{width:100%;}
.top{width:100%;}
.main{position:relative;}
.left{width:200px; position:absolute; left: 0; top: 0; height:510px;}
.right{margin:0px 0px 0px 210px; height:500px;}
.foot{width:100%;}
.top{height:100px;background:#cfcfcf;}
.main{background:red;}
.left{width:200px;height:600px;background:blue; position:absolute; top:100px; left:0px;}
.right{background:#7bc69f;width:100%; margin:0 0 0 205px; height:600px;}
.foot{background:#e37411;}
.main{background:red;}
.left{width:200px;height:600px;background:blue; position:absolute; top:100px; left:0px;}
.right{background:#7bc69f;width:100%; margin:0 0 0 205px; height:600px;}
.foot{background:#e37411;}
.top{height:80px;margin:0 auto;background:gray;}
.main{height:500px;background:red;position:relative;}
.left{ width:200px;background:blue;height:500px;position:absolute;top:0;left:0;}
.right{width:100%;background:cyan;height:500px;margin:0 0 0 210px;}
.foot{bottom:0;height:50px;background:orange;}
.main{height:500px;background:red;position:relative;}
.left{ width:200px;background:blue;height:500px;position:absolute;top:0;left:0;}
.right{width:100%;background:cyan;height:500px;margin:0 0 0 210px;}
.foot{bottom:0;height:50px;background:orange;}
最新回答 / Chuan_wei
这个案例是不定宽水平居中!没有设置width属性所以不能使用margin:0 auto;案例要求是:使main水平居中在浏览器中央,并不是严格意义上的mian居中。当然了,如果真的要居中的话可以设置body宽度,在设置left,right的宽度,使得main的位置就是body的正中间位置
2016-03-21