三栏布局中间自适应
一、使用flex布局
.outer{
display: flex;
width: 100%;
}
.outer>div{
height: 200px;
}
.left{
width: 200px;
background-color: red;
}
.center{
flex: 1;
background-color: skyblue;
}
.right{
width: 200px;
background-color: greenyellow;
}
<div class="outer">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
二、使用float
.outer{
width: 100%;
min-width: 600px;
}
.outer>div{
height: 200px;
}
.left{
float: left;
width: 200px;
background-color: red;
}
.right{
float: right;
width: 200px;
background-color: skyblue;
}
.center{
float: left;
width:calc(100% - 400px);
background-color: yellowgreen;
}
<div class="outer">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div>
三、使用position
.outer{
position: relative;
width: 100%;
min-width: 600px;
}
.outer>div{
position: absolute;
height: 200px;
top: 0;
}
.left{
width: 200px;
left: 0;
background-color: orange;
}
.right{
width: 200px;
right: 0;
background-color: orange;
}
.center{
left: 200px;
right: 200px;
background-color: skyblue;
}
<div class="outer">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
四、使用table布局
.outer{
display: table;
width: 100%;
min-width: 600px;
}
.outer>div{
height: 200px;
}
.left{
width: 200px;
background-color: red;
}
.right{
width: 200px;
background-color: greenyellow;
}
.center{
display: table-cell;
width: 100%;
background-color: skyblue;
}
<div class="outer">
<div class="left"></div>
<div class="center"></div>
<div class="right"></div>
</div>
五、使用grid布局
.outer{
display: grid;
grid-template-columns: 200px auto 200px;
grid-template-rows: 200px;
}
.inner{
background-color: orange;
}
.middle{
background-color: skyblue;
}
<div class="outer">
<div class="inner"></div>
<div class="inner middle"></div>
<div class="inner"></div>
</div>
六、使用双飞翼布局
.outer{
width: 100%;
}
.outer>div{
float: left;
}
.middle{
width: 100%;
height: 200px;
background-color: red;
}
.left{
width: 200px;
height: 200px;
background-color: skyblue;
margin-left: -100%;
}
.right{
width: 200px;
height: 200px;
margin-left: -200px;
background-color: orange;
}
<div class="outer">
<div class="middle"></div>
<div class="left"></div>
<div class="right"></div>
</div>