css圣杯等高布局
- 三列布局
- 左右固定,中间自适应
- 中间内容优先加载
- 左右和中间等高(伪等高)
*三列都需要浮动
*使用margin-left为负设定边界(元素位置不改变)
*左右使用定位,使中间的内容显示
*使用padding-bottom和margin-bottom设置伪等高
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>圣杯布局</title>
<style>
.header{
background-color: #1be497;
color: #fff;
height: 50px;
border: 1px solid black;
}
.footer {
background-color: #1be497;
color: #fff;
height: 50px;
border: 1px solid black;
}
.left,.right {
/* float: left; */
background-color: #fb7400;
color: #fff;
}
.middle {
float: left;
width: 100%;
background-color: #f7b400;
}
.left {
position: relative;
left: -200px;
width: 200px;
float: left;
margin-left: -100%;
padding-bottom: 10000px;
margin-bottom: -10000px;
}
.right {
width: 200px;
float: left;
margin-left: -200px;
position: relative;
right: -200px;
/* 等高布局 */
padding-bottom: 10000px;
margin-bottom: -10000px;
}
.clearfix::after {
content: '';
display: block;
clear: both;
}
.container {
padding: 0 200px;
overflow: hidden;
}
</style>
</head>
<body>
<div class="header">header</div>
<div class="container clearfix">
<div class="middle">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab laboriosam iste tempore minima aliquam voluptatem, recusandae illum quidem, optio vero sunt, enim et labore saepe dignissimos explicabo harum porro. Nesciunt.</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
<div class="footer">footer</div>
</body>
</html>