1、圣杯布局
上面这个链接讲的非常清晰,下面是我实现的代码
<!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>
</head>
<style>
#header,
#footer {
background: rgba(29, 27, 27, 0.726);
text-align: center;
height: 60px;
line-height: 60px;
clear: both;
}
#content {
overflow: hidden;
padding: 0 200px;
}
.column {
height: 200px;
float: left;
position: relative;
}
#middle {
background: rgba(250, 3, 3, 0.726);
width: 100%;
}
#left {
background: rgba(236, 200, 81, 0.726);
width: 200px;
margin-left: -100%;
left: -200px;
}
#right {
background: rgba(77, 104, 255, 0.726);
width: 200px;
margin-left: -200px;
left: 200px;
}
</style>
<body>
<div id="header">#header</div>
<div id="content">
<div id="middle" class="column">#middle</div>
<div id="left" class="column">#left</div>
<div id="right" class="column">#right</div>
</div>
<div id="footer">#footer</div>
</body>
</html>
2、双飞翼布局
css经典布局——双飞翼布局_越努力,越幸运!-CSDN博客_双飞翼布局
双飞翼布局其实和圣杯布局的精髓是一样的,都是通过设置负margin来实现元素的排布,不同的就是html结构,双飞翼是在center元素内部又设置了一层inner-center的元素并设置它的左右margin,而非圣杯布局的padding,来排除两边元素的覆盖。所以这两种布局原理基本一样,关键就是在于设置负margin的技巧,和元素浮动的相对定位技巧来实现。
<!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>
</head>
<style>
#header,
#footer {
background: rgba(29, 27, 27, 0.726);
text-align: center;
height: 60px;
line-height: 60px;
clear: both;
}
#content {
overflow: hidden;
padding: 0 200px;
}
.column {
height: 200px;
float: left;
position: relative;
}
#middle {
background: rgba(250, 3, 3, 0.726);
width: 100%;
}
#left {
background: rgba(236, 200, 81, 0.726);
width: 200px;
margin-left: -100%;
left: -200px;
}
#right {
background: rgba(77, 104, 255, 0.726);
width: 200px;
margin-left: -200px;
left: 200px;
}
</style>
<body>
<div id="header">#header</div>
<div id="content">
<div id="middle" class="column">#middle</div>
<div id="left" class="column">#left</div>
<div id="right" class="column">#right</div>
</div>
<div id="footer">#footer</div>
</body>
</html>