左中右三栏布局,中间自适应
下面将介绍三种方法实现这种布局
第一种当然是定位了
父级相对定位(relative),左右子元素绝对定位(absolute)
中间盒子要设置左右margin值,值为左右盒子宽度,设置padding也行
为什么呢?因为绝对定位元素脱离了普通文档流了(就像飘在上面一样)
<head>
<style>
.container{
position: relative;
min-width: 600px;
padding: 100px;
box-sizing: border-box;
background-color:rgba(0,0,0, .4);
}
.box-left{
position: absolute;
top: 100px;
left: 100px;
width: 100px;
height: 100px;
background-color: rgba(145, 5, 145, .4);
}
.box-right{
position: absolute;
top: 100px;
right: 100px;
width: 100px;
height: 100px;
background-color: rgba(56, 56, 245, .4);
}
.box-center{
height<