JS Control Div Center Align

Source: Internet
Author: User

Do you really think the center alignment is so simple that we're going to get a level now, after all, it's a little hard to play.

<div id= "hz_qxalert1_id" style= "position:fixed; top:0px; left:0px; right:0px; bottom:0px; z-index:999; Display:block; width:100%; height:100%; Background:rgba (0, 0, 0, 0.701961); " >
<div id= "Hz_qxalert1_id_next" style= "width:400px; height:203px; padding:0px 0px 20px; Position:absolute; top:248px; left:484px; z-index:500; BORDER:1PX solid RGB (22, 138, 187); border-radius:5px; Overflow:hidden; Display:block; Background:rgb (255, 255, 255); " >
<p style= "padding:0 0 0 28px;text-align:left; height:50px; line-height:50px; z-index:500; " > News Consultation </p>
<p class= "Alert_text" style= "height:80px; line-height:80px; Z-index:500;text-align:center; " > Will you cancel the consultation and confirm the cancellation? </p>
<button onclick= "Enterout ()" class= "Btn1" style= "z-index:500;height:30px; Outline:none;text-align:center;background: #168ABB; Border:0;color: #fff; border-radius:5px;width:89px;margin-left:185px; " > is </button>
<button class= "btn1" style= "height:30px; Outline:none;text-align:center;background: #168ABB; Border:0;color: #fff; border-radius:5px;width:89px; z-index:500; " > No </button>
</div>
</div>

Like this code pop-up Modal box, how to let the middle White Block center alignment, the code is as follows

Gets the width and height of the black matte layer
var modelwidth = $ (' #hz_qxalert1_id '). width ();
var modelheight= $ (' #hz_qxalert1_id '). Height ();

Gets the width and height of the Cancel consultation confirmation box
var alertwidth = $ (' #hz_qxalert1_id_next '). width ();
var alertheight= $ (' #hz_qxalert1_id_next '). Height ();

Make the Cancel consultation confirmation box centered relative to the modal box
Parent.document.getElementById (' Hz_qxalert1_id_next '). Style.left = (modelwidth-alertwidth)/2+ "px";
Parent.document.getElementById (' Hz_qxalert1_id_next '). Style.top = (modelheight-alertheight)/2+ "px";

Let the confirmation box for the canceled consultation show up.
document.getElementById (' Hz_qxalert1_id_next '). Style.display = "block";

JS Control Div Center Align

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.