absolute 绝对定位来居中
- 先让元素左上角居中
top: 50%;
left: 50%;
- 再根据容器的大小来设置外边距偏移量
width: 800px;
height: 500px;
margin-left: -400px;
margin-top: -250px;
拓展:过渡玩法:
background-size: cover;
background-size: 100% 100%;
background-position: center;
background-attachment: fixed;
transition: background-size 2s cubic-bezier(0, .98, .33, 1.1);
标签:居中,top,50%,background,css,size
From: https://www.cnblogs.com/tobycold/p/17793077.html