1.绝对定位法
HTML:
<body>
<div class="box"></div>
</body>
CSS:
<style>
.box{
position:absolute;
top:0;
bottom: 0;
left:0;
right: 0;
margin: auto;
width:100px;
height:100px;
background:red;
}
</style>
2.margin负值法
HTML:
<body>
<div class="box"></div>
</body>
CSS:
<style>
.box{
position:absolute;
top:50%;
left:50%;
margin-left: -50px;
margin-top:-50px;
width:100px;
height:100px;
background:red;
}
</style>