Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to position the div popup dialog to the center of browser screen?

I need to position div popup to the center of browser screen ( no matter what size the screen is). And I want to keep the position as absolute as I don't want to move the popup down when I scroll down the page.

This div is displayed when button is clicked using Jquery.

I tried setting margin-left to half of the width like mentioned in other posts but It isn't working for me.

Here is my code

CSS code:

.holder{        
    width:100%;
    position:absolute;
    left:0;
    top:0px;
    display:block;  
}
.popup{
    width:800px;
    margin:0 auto;
    border-radius: 7px;
    background:#6b6a63;
    margin:30px auto 0;
    padding:6px;
}

.content{
    background:#fff;
    padding: 28px 26px 33px 25px;
}

HTML Code:

  <div class="holder">
        <div id="popup" class="popup">            
            <div class="content">
                        some lengthy text
                     </div>
        </div>
   </div>

Thanks!!

like image 472
S K Avatar asked Jan 06 '12 20:01

S K


1 Answers

.popup-content-box{
    position:fixed;
    left: 50%;
    top: 50%;
    -ms-transform: translate(-50%,-50%);
    -moz-transform:translate(-50%,-50%);
    -webkit-transform: translate(-50%,-50%);
     transform: translate(-50%,-50%);
}
like image 139
Nikhil Mathew Avatar answered Nov 16 '22 04:11

Nikhil Mathew