两边定宽,中间自适应的三栏布局,中间栏要放在文档流前面以优先渲染。
<div class="content">
<div class="center col">
</div>
<div class="left col">
</div>
<div class="right col">
</div>
</div>第一步:定义容器content的样式padding: 0 100px,以及center,left,right的公共样式,同时定义每个容器的颜色和宽度,左右固定一百,中间100%;
.content{padding: 0 100px;}
.col{
float: left;
height: 200px;
position: relative;
}
.left,.right{
width: 100px;
}
.left{
background-color: blue;
}
.right{
background-color: green;
}
.center{
width: 100%;
background-color: pink;
}效果图:

第二步:采用负边距将left和right放到左右两边 1. 当左右设置不同方向负边距margin-left和margin-right
.left{margin-left:-100%;}
.right{margin-right:-100px;}.left{margin-left:-100%;}
.right{margin-left:-100px;}效果图:

此时我们可以清晰的看到center的左右两边都被left和center遮挡,此时圣杯布局如何处理呢? 第三步:用相对定位来解决 1. 当左右设置不同方向负边距margin-left和margin-right
.left{right:100px;}.left{right:100px;}
.right{left:100px;}效果图:

1. 当左右设置不同方向负边距margin-left和margin-right
.content{padding: 0 100px;}
.col{
float: left;
height: 200px;
position: relative;
}
.left,.right{
width: 100px;
}
.left{
background-color: blue;
margin-left: -100%;
right: 100px;
}
.right{
background-color: green;
margin-right: -100px;
}
.center{
width: 100%;
background-color: pink;
}.content{padding: 0 100px;}
.col{
float: left;
height: 200px;
position: relative;
}
.left,.right{
width: 100px;
}
.left{
background-color: blue;
margin-left: -100%;
right: 100px;
}
.right{
background-color: green;
margin-left: -100px;
left:100px;
}
.center{
width: 100%;
background-color: pink;
}优点:
缺点: