HTML-how to use css on the mobile terminal to align the horizontal and vertical la s of percentage la S, html-css

Source: Internet
Author: User

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 ~

 

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.