PC-side let a pop-up window horizontal and vertical center, in the knowledge that the window width is very good calculation, only need to use the following CSS:
| 123456789 |
#date{ width: 300px; height: 300px; position: absolute; top: 50%; left: 50%; margin-left: -150px; margin-top: -150px;} |
But to the mobile side, if write percent layout, height is not OK, so the center of the window will become difficult
| 1234567891011 |
.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 and get the effect you want,
But if we do not determine the height of the case, the height:30% removed, do not set the height of the value, will find that the pop-up window will be based on their own content to achieve vertical center, the main CSS code is as follows:
| 12345678910 |
.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 section is a gray background area):
html-how to use CSS to align the pop-up window horizontally and vertically in a percentage layout