css实现三栏布局,两边固定,中间自适应

一、HTML部分

1
2
3

二、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;}

你可能感兴趣的:(css实现三栏布局,两边固定,中间自适应)