一、两列布局
1、利用BFC
<div class="left">
left
</div>
<div class="right">
right
</div>
* { padding: 0; margin: 0;}
.left{
float: left;
width: 200px;
height: 800px;
background-color: blueviolet;
}
.right{
overflow: hidden;
height: 800px;
background-color: blue;
}
2、利用绝对定位
* { padding: 0; margin: 0;}
.left{
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 800px;
background-color: blueviolet;
}
.right{
height: 800px;
background-color: blue;
margin-left: 200px;
}
二、三列布局
1、两边固定,中间自适应
(1)使用绝对定位
<div class="left">
left
</div>
<div class="center">center</div>
<div class="right">
right
</div>
* { padding: 0; margin: 0;}
.left{
position: absolute;
left: 0;
top: 0;
width: 200px;
height: 800px;
background-color: blueviolet;
}
.center{
width:auto;
height: 800px;
background-color: green;
}
.right{
position: absolute;
right: 0;
top: 0;
width: 200px;
height: 800px;
background-color: blue;
}
(2)利用浮动
<div class="left">
left
</div>
<div class="right">
right
</div>
<div class="center">center</div>
* { padding: 0; margin: 0;}
.left{
float: left;
width: 200px;
height: 800px;
background-color: blueviolet;
}
.center{
width: auto;
height: 800px;
background-color: green;
margin-left: 200px;
margin-right: 200px;
}
.right{
float: right;
width: 200px;
height: 800px;
background-color: blue;
}
2、中间固定,两边宽度自适应
<div id="left">
<div>left</div>
</div>
<div id="center">center</div>
<div id="right">
<div>right</div>
</div>
* { padding: 0; margin: 0;}
#center { width: 600px; background: red; margin: 0 auto;height: 800px}
#left { position: absolute; top: 0; left: 0;width: 50%;}
#right { position: absolute; top: 0; right: 0; width: 50%;}
#left div { margin-right: 300px; position: relative; background: lime;height: 800px}
#right div { margin-left: 300px; position: relative; background: lime;height: 800px}