Two-column layout
-
Description: a fixed column width of a column adaptive. Benefits like this do is to set the column width can advertise, adaptation can be used as the main content.
-
Implementation: ① float + margin ② using the absolute position of
例: float+margin
<body>
<div class="left">定宽</div>
<div class="right">自适应</div>
</body>
.left{
width: 200px;
height: 600px;
background: red;
float: left;
display: table;
text-align: center;
line-height: 600px;
color: #fff;
}
.right{
margin-left: 210px;
height: 600px;
background: yellow;
text-align: center;
line-height: 600px;
}
Three-column layout
-
Features: fixed width on both sides, then the middle of the width is auto, the content can be adaptive, margin plus margin, to set
-
Method to realize:
-
Use the left and right columns using the float property, the middle column using the margin attribute distraction
-
Positioning achieved using the position, i.e., left and right two columns using the position for positioning, the intermediate column used for positioning margin
-
例: float+margin
<body>
<div class="left">左栏</div>
<div class="right">右栏</div>
<div class="middle">中间栏</div>
</body>
.left{
width: 200px;
height: 300px;
background: yellow;
float: left;
}
.right{
width: 150px;
height: 300px;
background: green;
float: right;
}
.middle{
height: 300px;
background: red;
margin-left: 220px;
margin-right: 160px;
}
例:position +magin
<body>
<div class="left">左栏</div>
<div class="middle">中间栏</div>
<div class="right">右栏</div>
</body>
.left{
background: yellow;
width: 200px;
height: 300px;
position: absolute;
top: 0;
left: 0;
}
.middle{
height: 300px;
margin: 0 220px;
background: red;
}
.right{
height: 300px;
width: 200px;
position: absolute;
top: 0;
right: 0;
background: green;
}
Elastic layout
- Description: Elastic box (flexbox) layout is a layout as a method designed to unidimensional. One-dimensional content that you want to be in rows or columns layout. You can use display: flex to become the elastic element layout
例:
.container {
display: flex;
}
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
注:该容器的直接子元素会变为弹性项(flex item),并按行排列