假设元素长宽均为100px,使其水平垂直居中有两种方法
1.
.item{
position:absolute;
left:50%;
top:50%;
margin-left:-50px;/*100px的一半*/
margin-top:-50px;/*100px的一半*/
}
2.
.item{
position:absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin:auto;
}
假设元素长宽均为100px,使其水平垂直居中有两种方法
1.
.item{
position:absolute;
left:50%;
top:50%;
margin-left:-50px;/*100px的一半*/
margin-top:-50px;/*100px的一半*/
}
2.
.item{
position:absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin:auto;
}