一、HTML部分
<div class="body">
<div class="left">1</div>
<div class="center">2</div>
<div class="right">3</div>
</div>
二、CSS部分
1.flex布局
.body{
width: 100%;
display: flex;
justify-content: center;
}
.body div{
background-color: #f00;
margin: 10px;
height: 200px;
}
.left,.right{width: 200px;}
.center{
flex: 1;
}
2.绝对定位
.body div{
background-color: #f00;
height: 200px;
}
.left{
width: 200px;
position: absolute;
left: 0;
top: 0;
}
.right{
width: 200px;
position: absolute;
right: 0;
top: 0;
}
.center{
margin: 0px 210px;
}
3.浮动和宽度计算,中间宽度等于总宽度减去两边div宽度,再减去magin距离
.body{
overflow: hidden;
}
.body div{
background-color: #f00;
height: 200px;
float: left;
}
.left,.right{width: 200px}
.center{width: calc(100% - 410px);margin: 0 5px;}
网友评论