一.圣杯布局
1.圣杯布局的效果和要求
效果

要求
- 头部和底部固定高度,宽度占100%
- 中间的container是一个三栏布局,即左右固定宽高,中间自适应
- container的高度要占到页面的大部分
2.圣杯布局的实现方式[重要]
2.1.使用浮动实现圣杯布局
思路
- step1:设置头部和底部的样式
- step2:设置container的三列布局:子元素都设置浮动和相对定位,注意要把center放最前,同时footer要清除浮动
- step3:container的左右子元素设置固定宽度,中间元素宽度设置为100%
- step4:此时左右子盒子被挤压到下一行,left要设置margin-left:-100%让它回到上一行
- step5:left移上去后会遮挡center的内容,需为container父盒子设置左右padding分别为left和right的宽度
- step6:把右侧right也提上去
代码
<style>
* {
margin: 0;
padding: 0;
}
.header,.footer {
background: #339999;
text-align: center;
height: 50px;
line-height: 50px;
}
.footer {
clear: both;
}
.container {
padding-left: 200px;
padding-right: 200px;
text-align: center;
line-height: 100px;
}
.container>*{
width: 200px;
height: 100px;
float:left;
position: relative;
}
.center {
background: #336666;
width: 100% !important;
position: relative;
}
.left {
background: #336699;
margin-left: -100%;
right: 200px;
}
.right {
background