HTML-how to use css on the mobile terminal to align the horizontal and vertical la s of percentage la S, html-css
The pc end center the horizontal and vertical directions of a pop-up window. It is well calculated when the pop-up window width is high. You only need to use the following css:
#date{ width: 300px; height: 300px; position: absolute; top: 50%; left: 50%; margin-left: -150px; margin-top: -150px;}
But on the mobile end, if the percentage layout is written, the height is difficult to determine, so it will become difficult to center the window. Today, Baidu has encountered this problem and saw the information of this friend, the friend's css code is as follows:
.center{ width:50%; height:30%; position: absolute; top: 50%; left: 50%; -moz-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
Try it to get the desired effect,
However, if we remove height: 30% without setting the height value, we will find that the window will center vertically based on our own content, the main css code is as follows:
.center{ width:50%; position: absolute; top: 50%; left: 50%; -moz-transform: translate(-50%, -50%); -ms-transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%); transform: translate(-50%, -50%);}
The effect is as follows (the pop-up window area is the gray background area ):
In this way, you can get the expected pop-up window with the center in both the horizontal and vertical directions. You can try it ~