一、子元素相对于父元素做定位
给父元素加position:relative
给子元素加position:absolute
二、垂直水平居中
设定position: absolute;然后再调整定位和margin属性实现垂直水平居中,有以下两种方法
1.
.box{
width:200px;
height: 200px;
background: red;
position: absolute;
left:50%;
top:50%;
margin-left:-100px;
margin-top:-100px;
}
2.{
.box{
width:200px;
height: 200px;
background: blue;
position: absolute;
top:0;
bottom:0;
left:0;
right:0;
margin:auto;
}