一: 右側固定寬度 左側自適應
第一種:左側用margin-right,右側float:right 就可以實現。
HTML代碼可以如下寫:
<div class="box-left">
<a href="" target="_blank">我是龍恩</a>
</div>
<div class="box-right">
<a href="" target="_blank">我是龍恩</a>
</div>
CSS代碼可以如下寫:
.box-left{height:300px;margin-right:300px;background:#DDD;}
.box-right{width:300px;height:300px;float:right;background:#AAA;}
如上代碼就可以實現效果。
第二種:左側同樣用margin-right 右側採用絕對定位 如下代碼所示:
HTML代碼如下:
<div class="bd">
<div class="bd-left">
<a href="" target="_blank">我是龍恩</a>
</div>
<div class="bd-right">
<a href="" target="_blank">我是龍恩</a>
</div>
</div>
CSS代碼如下:
.bd{position:relative;}
.bd-left{height:300px;;margin-right:300px;background:#DDD;}
.bd-right{width:300px;height:300px;position:absolute;top:0;right:0;background:#AAA;}
第三種:右側浮動 且 用負margin值
HTML代碼如下:
<div class="wrap">
<div class="wrap-left">
<div class="left-con">
<a href="" target="_blank">我是龍恩</a>
</div>
</div>
<div class="wrap-right">
<a href="" target="_blank">我是龍恩</a>
</div>
</div>
CSS代碼如下:
.wrap{overflow:hidden;background:#EEE;}
.wrap-right{width:300px;position:relative;float:right;margin-left:-300px;background:#AAA;}
.wrap-left{width:100%;float:left;}
.left-con{margin-right:300px;background:#DDD;}
.left-con,.wrap-right{height:300px;}
二:左右固定 中間自適應的情況
第一種:左右側採用浮動 中間採用margin-left 和 margin-right 方法。
<div style="width:100%; margin:0 auto;">
<div style="width:200px; float:right; background-color:#960">這是右側的內容 固定寬度</div>
<div style="width:150px; float:left; background:#6FF">這是左側的內容 固定寬度</div>
<div style="margin-left:150px;margin-right:200px; background-color:#9F3">中間內容,自適應寬度</div>
</div>
第二種:左右兩側採用絕對定位 中間同樣採用margin-left margin-right方法:
HTML代碼如下:
<div class="l-sidebar"></div>
<div class="mainbar"></div>
<div class="r-sidebar"></div>
CSS代碼如下:
.l-sidebar {
width:200px;
height:500px;
position:absolute;
top:0;
left:0;
background:blue;
}
.mainbar {
margin-left:200px;
height:500px;
margin-right:300px;
background:green;
}
.r-sidebar {
width:300px;
height:500px;
position:absolute;
top:0;
right:0;
background:blue;
}