css布局之左右固定宽度中间自适应

方法一:

左右布局用float,中间布局以左右布局的宽度为margin,这样就能自适应了。

左:float:left;width:300px;

右:float:right;width:300px;

中间:margin:0 300px;

 

方法二:

左右布局用position,中间布局以左右布局的宽度为margin,这样就能自适应了。

左:position:absolute; left:0; top:0width:300px;

右:position:absolute; top:0; right:0;width:300px;

中间:margin:0 300px;

 

方法三:

<style>
.demo3{
    margin-top: 30px;
}
.demo3 .l,
.demo3 .r,
.demo3 .m{
    float: left;
}
.demo3 .l,
.demo3 .r,
.demo3 .in{
    height: 300px;
}

.demo3 .m{
    width: 100%;
}
.demo3 .in{
    margin: 0 300px;
    background:#fcc;
}
.demo3 .l{
    width: 300px;
    margin-left: -100%;
    background:#9CF;
}
.demo3 .r{
    width: 300px;
    margin-left: -300px;
    background:#ccc;
}
</style>
<div class="demo3">
     <div class="m">
         <div class="in"></div>
     </div>
    <div class="l"></div>
     <div class="r"></div>
</div>
View Code

 

posted @ 2014-09-27 17:39  jellyANDjammy  阅读(166)  评论(0编辑  收藏  举报