版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27855219/article/details/89175149
1.fixed,从中间移动定位
position:fixed;width:200px;height:200px;left:50%;top:50%;
margin-left:-100px;margin-top:-100px
第一行设置完:盒子的左上角的点,刚好处于浏览器页面中间,需要向左向上移动才可实现整体的居中,所以margin-left=负的盒子宽的一半,margin-top=负的盒子高的一半
2.从左上利用margin:auto定位
{width:200px;
height:200px;
position:absolute;
top:0;left:0;
right:0;
bottom:0;
margin:auto;}