Using the Z-index property to implement a Web page popup box

Source: Internet
Author: User

Java Web application development process, some user action needs to be displayed in a popup box, today, the previous project development of the popup box implementation of the principle of a careful analysis, the use of CSS Z-index properties, you can achieve a simple popup box effect. Specific principle:

. mask{z-index:900; position:fixed!important; position:absolute; left:0px; top:0px; width:100%; height:100%;  

<!--current page content display div z-index min--><div class= "Shell" id= "content" ></div><!--Mask is responsible for the background to gray out, Z-index for--><div class= "mask" style= "Display:none;" ></div><!--pop-up box Div,z-index-900,div_op show at the top of the page--><div class= "box"  style= "display:none; position:absolute;top:50%;left:50%;width:520px;height:auto;z-index:999; margin: -150px 0px 0px-260px; "id=" Div_op "></div>

A user action that triggers $ (". Mask"). Show (); $ ("#div_op"). Show (), due to the z-index>content of the mask, and Div_op Z-index>mask, combined with the position attribute, set the popup position as the center part of the Web page, When the position of CSS is absolute, the specified top and left are equal to the location-related properties, and the margin adjusts div_op relative to the position of its parent element, and on the basis of top:50%;left:50%, moves the distance up and down, respectively. Causes the popup box to be centered eventually. The simple pop-up effect is as follows:


A simple example of an HTM file:


Using the Z-index property to implement a Web page popup box

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.