1 掌握盒子水平垂直居中的五大问题
.box{
width:100px
height:50px
position:absolute
top:50%
left:50%;
margin-top:-25px
margin-left:-50px
}
.box{
position:absolute
top:0
left:0;
rigin:0
bottom:0
margin: auto
}
.box{
position:absolute
top:50%
left:50%;
transform:translate(-50%,-50%)
}
- 使用 display:flex
- 使用 display:table-cell
body{
display:table-cell
vertical-align:middle
text-align:center
width:500px
height:500px
}
.box{
display:inline-block
}
2 css的盒子模型
- 标准盒子模型 (box-sizing:content-box)
content (width)+padding+margin+border - 怪异盒子模型(box-sizing:boder-box) 源码常用,不用计算
content (width+padding+margin+border) - flex 盒子模型
3 左右固定 ,中间自适应
- 圣杯布局:浮动和margin clearfix( 清除浮动)
<div class='content clearfix' >
<div class='center'></div>
<div class='left'></div>
<div class='right'></div>
</div>
.content{
height:100%
padding: 0 200px
}
.left
.right{
width:200px
float:left
}
.center{
width:100%
float:left
}
.left{
margin-left:-100%
position:relative
left:-200px
}
.right{
margin-right:-200px
}
<div class='content'>
<div class='center'></div>
</div>
<div class='left'></div>
<div class='right'></div>
.left
.right
.content{
float:left
}
.content{
width:100%
}
.content center{
margin: 0 200px
}
.left
.right{
width:200px
}
.left{
margin-left:-100%
position:relative
left:-200px
}
right{
margin-right:-200px
}
width:calc(100% - 400px)
<div class='content' >
<div class='left'></div>
<div class='center'></div>
<div class='right'></div>
</div>
.content {
display:flex
justify-content:space-between
}
.left
.right{
width:200px
flex: 0 0 200px
}
.center{
flex:1
}
<div class='content' >
<div class='left'></div>
<div class='center'></div>
<div class='right'></div>
</div>
.content {
position:relative
}
.left
.right{
position: absolute
top:0
width:200px
}
.left{
left:0
}
.right{
right:0
}
.center{
margin: 0 200px
}