圣杯布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>圣杯布局</title>
<style>
.header,
.footer {
text-align: center;
background-color: aqua;
color: blue;
}
.footer {
clear: both;
}
.active {
float: left
}
.box {
padding-left: 300px;
padding-right: 300px;
}
.main {
width: 100%;
height: 300px;
background-color: orangered;
}
.left {
width: 300px;
height: 300px;
background-color: blueviolet;
margin-left: -100%;
position: relative;
right: 300px;
}
.right {
width: 300px;
height: 300px;
background-color: yellowgreen;
margin-right: -300px;
}
</style>
</head>
<body>
<div class="header">header</div>
<div class='box'>
<div class='main active'>main</div>
<div class='left active'>left</div>
<div class='right active'>right</div>
</div>
<div class="footer">footer</div>
</body>
</html>
双飞翼布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>双飞翼布局</title>
<style>
.main {
width: 100%;
background-color:aquamarine;
height: 300px;
}
.main-item {
padding: 0 300px;
height: 100%;
word-break: break-all;
}
.left {
width: 300px;
height: 300px;
background-color:bisque;
margin-left: -100%;
}
.right {
width: 300px;
height: 300px;
background-color:chartreuse;
margin-left:-300px;
}
.active {
float: left;
}
</style>
</head>
<body>
<div class="main active">
<p class="main-item">mainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmainmain</p>
</div>
<div class="left active">left</div>
<div class="right active">right</div>
</body>
</html>
对比
- 圣杯布局对比双飞翼布局多了相对定位
- 双飞翼只运用了margin+float就实现三列布局
- 双飞翼去掉了外部包裹的标签,在main中新增了一个标签