HTML
<body>
<div class="box"></div>
</body>
Flex布局
body{
display: flex;
justify-content:center;
align-items: center;
height: 100vh;
}
.box{
width: 100px;
height: 100px;
background: #000000;
}
定位方案
body{
height:100vh;
}
.box{
position: absolute;
left: 0;
bottom: 0;
right: 0;
top: 0;
margin: auto;
}
margin位移方案
<style>
body{
height:100vh;
/*vh.vw IE9以上*/
}
.box{
position: absolute;
left: 50%;
top: 50%;
margin-left: -50px;
margin-top: -50px;
width: 100px;
height: 100px;
background: #000;
}
</style>
css3位移方案
<style>
body{
height:100vh;
/*vh.vw IE9以上*/
}
.box{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
width: 100px;
height: 100px;
background: #000;
}
</style>