一:圣杯布局
重点:content的padding,left的margin-left和left值,right的margin-left和right值:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>圣杯布局</title>
<style>
* {
text-align: center;
}
.header {
height: 50px;
line-height: 50px;
background-color: #ff6666;
}
.content {
background-color: lightblue;
padding: 0 200px; /* √ */
overflow: hidden; /* 清除浮动 */
}
.content .main{
width: 100%;
height: 300px;
line-height: 300px;
float: left;
background-color: lightcoral;
}
.content .left, .content .right {
float: left;
width: 180px;
height: 300px;
line-height: 300px;
background-color: antiquewhite;
position: relative; /* √ */
}
.content .left {
margin-left: -100%; /* √ */
left: -200px; /* √ */
}
.content .right {
margin-left: -180px; /* √ */
right: -200px; /* √ */
}
.footer {
height: 50px;
line-height: 50px;
background-color: lightgreen;
}
</style>
</head>
<body>
<div>
<!--头部-->
<div class="header">header</div>
<!--主题内容-->
<div class="content">
<div class="main">main</div> <!-- 将main放在前面让其先加载出来 -->
<div class="left">left</div>
<div class="right">right</div>
</div>
<!--// 底部-->
<div class="footer">footer</div>
</div>
</body>
</html>
页面效果:
二、双飞翼布局
重点:main外面包了一层main-wrap,main-warp的宽度、浮动,main的margin,left、right的margin-left。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>双飞翼布局</title>
<style>
* {
text-align: center;
}
.header {
height: 50px;
line-height: 50px;
background-color: #ff6666;
}
.content {
background-color: lightblue;
overflow: hidden; /* 清除浮动 */
}
.content .main-wrap { /* √ */
width: 100%;
float: left;
}
.content .main-wrap .main{
height: 300px;
margin: 0 200px; /* √ */
line-height: 300px;
background-color: lightcoral;
}
.content .left, .content .right {
float: left;
width: 180px;
height: 300px;
line-height: 300px;
background-color: antiquewhite;
}
.content .left {
margin-left: -100%; /* √ */
}
.content .right {
margin-left: -180px; /* √ */
}
.footer {
height: 50px;
line-height: 50px;
background-color: lightgreen;
}
</style>
</head>
<body>
<div>
<!--头部-->
<div class="header">header</div>
<!--主题内容-->
<div class="content">
<div class="main-wrap">
<div class="main">main</div> <!-- 将main放在前面让其先加载出来 -->
</div>
<div class="left">left</div>
<div class="right">right</div>
</div>
<!--// 底部-->
<div class="footer">footer</div>
</div>
</body>
</html>
页面效果: