html-how to use CSS to align the pop-up window horizontally and vertically in a percentage layout

Source: Internet
Author: User

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:

#date {        width:300px;       height:300px;    Position:absolute;        top:50%;        left:50%;        Margin-left: -150px;        Margin-top: -150px;}

But to the mobile side, if write percentage layout, height is not OK, so the center of the window will become difficult, today encountered this problem, Baidu a bit, see this friend's information, (http://www.shejidaren.com/ centering-percentage-widhtheight-layout.html), this 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 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:

. 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):

This can be very good to get what you want, horizontal and vertical center of the pop-up window effect pull, we can try ~

html-how to use CSS to align the pop-up window horizontally and vertically in a percentage layout

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.