Use js to get the window size and element position, and then set the content position according to the obtained values. Pure css can also be used, but it feels not flexible enough
1. CSS implementation method (width and height are known in advance): The layer that needs to be centered uses absolute positioning, and combines left, top, margin-left and margin-top to achieve centering. 2. js implementation, I won’t say much about this.
Use js to get the window size and element position, and then set the content position according to the obtained values. Pure css can also be used, but it feels not flexible enough
Recommend your own blog: http://blog.csdn.net/zp1996323/article/details/50936259, the effect achieved is vertical centering and horizontal centering
margin-right:auto;
margin-left:auto
position: absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
width:XXpx;
height:XXpx;
1. CSS implementation method (width and height are known in advance): The layer that needs to be centered uses absolute positioning, and combines left, top, margin-left and margin-top to achieve centering.
2. js implementation, I won’t say much about this.