Directory:
One, horizontal layout
Two, vertical layout
Three, two-column layout
Four-, three-column layout
Five, multi-column layout
Six, equal height layout
One, horizontal layout
1,text-align
. Parent{ text-align: center; } .Child { display: inline-block; }
2,margin
.Child { width: 200px; Margin: 0 auto; }
3,position
. Parent{ position: relative; } .Child { position: absolute; left: 50%; width: 200px; margin-left: -100px; }
4,table
.Child { display: table; Margin: 0 auto; }
5,flex
1) justify-content
. Parent{ display: flex; Justify-content: center; }
2) margin
. Parent{ display: flex; } .Child { margin: 0 auto; }
Two, vertical layout
1,position
. Parent{ position: relative; } .Child { position: absolute; Top: 50%; height: 200px; margin-top: -100px; }
2,flex
1), Align-items
. Parent{ display: flex; Align-items: center; }
2), margin
. Parent{ display: flex; } .Child { margin: auto 0; }
Three, two-column layout
1, left fixed width, right adaptive
. Parent::after{ content: '; Clear: both; display: table; } .Left { float: left; Width: 200px; } . Main{ margin-left: 200px; }
{ display: table; table-layout: fixed; width: 100%; } {width: 100px; } . Left, { display: table-cell; }
2, left adaptive, right adaptive
. Parent::after{ content: '; Clear: both; display: table; } .Left { float: left; } . Main{ overflow:hidden; }
Four-, three-column layout
Fixed width on both sides, intermediate adaptive
1,float+margin
<style>. Parent::after{content:"';Clear:both;Display:Table; }. Left{float: Left;width:200px; }. Center{margin:0 200px; }. Right{float: Right;width:200px; }</style>
2,position+margin
<style>. Left{position:Absolute;Top:0; Left:0;width:200px; }. Right{position:Absolute;Top:0; Right:0;width:200px; }. Center{margin:0 210px; }</style><body> <div class= "left" > Right </div> <div class= "center" > in </div> < Div class= "Right" > R </div></body>
Five, multi-column layout
1, Negative margin
{ margin-left: -20px }/ * assume that the spacing between columns is 20px* / { float: left; Width: 25%; padding-left: 20px; box-sizing: border-box; }
2,flex
{ display: flex; } {flex: 1; } {margin-left: 20px; }
CSS Typical layout