方式一
优点:不用给html设置100%,宽度不固定
position: absolute;
left: 0;
right: 0;
top: 50%;
transform: translateY(-50%);
方式二:
使用flex
html,body{
height:100%;
width:100%
}
.div{
display: flex;
width: 100%;
height: 100%;
justify-content: center;
flex-direction: column;
}
还有其他一些宽高固定的方式。