The holy grail layout
<! doctypehtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="Width =device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
padding: 0;
margin: 0;
}
.container {
padding-left: 200px;
padding-right: 200px;
}
.left {
float: left;
width: 200px;
height: 400px;
background: red;
margin-left: -100%;
position: relative;
left: -200px;
}
.center {
float: left;
width: 100%;
height: 400px;
background: yellow;
}
.right {
float: left;
width: 200px;
height: 400px;
background: blue;
margin-left: -200px;
position: relative;
right: -200px;
}
</style>
</head>
<body>
<section class="container">
<div class="center"></div>
<div class="left"></div>
<div class="right"></div>
</section>
</body>
</html>
Copy the code
steps
- write
center
Part,width 100%
center
.left
.right
Both float to the left- The parent container
container
Set up thepadding-left
andpadding-right
- Set up the
margin-left
Negative letleft
andright
Partial return tocenter
Part of the same line - Set relative positioning, let
left
andright
Move the parts to the sides
disadvantages
- The minimum width of the center section cannot be less than the width of the left section
- The height of one column is elongated, and the height of the other two columns is not automatically filled
Twin wing layout
<! doctypehtml>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="Width =device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>* {padding: 0;
margin: 0;
}
.container {
min-width: 600px;
}
.left {
float: left;
width: 200px;
height: 400px;
background: red;
margin-left: -100%;
}
.center {
float: left;
width: 100%;
height: 400px;
background: yellow;
}
.center .inner {
margin: 0 200px;
}
.right {
float: left;
width: 200px;
height: 400px;
background: blue;
margin-left: -200px;
}
</style>
</head>
<body>
<section class="container">
<div class="center">
<div class="inner">Twin wing layout</div>
</div>
<div class="left"></div>
<div class="right"></div>
</section>
</body>
</html>
Copy the code
steps
- write
center
Part,width 100%
center
.left
.right
Both float to the leftcenter
Add an inner layer to the sectiondiv
And set upmargin-left
.margin-right
- Set up the
margin-left
Negative letleft
andright
Partial return tocenter
Part of the same line
disadvantages
- Add a layer of
dom
Tree node