html中实现div居中定位的方法:CSS部分代码如下:
css代码如下:
方法(1):
.test {
width:100px;
height:100px;
background:#000;
position:absolute;
left:0;
top:0;
margin-left:-50px;
margin-top:-50px;
}
方法(2):
.test {
width:120px;
height:120px;
position:absolute;
margin:auto;
left:0;
right:0;
top:0;
bottom:0;
}
方法(3):
.test {
width:100px;
height:100px;
position:absolute;
left:50%;
top:50%;
transform:translate(-50%,-50%);
-webkit-transform:translate(-50%,-50%);
-moz-transform:translate(-50%,-50%);
-ms-transform:translate(-50%,-50%);
-o-transform:translate(-50%,-50%);
}