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!!
Here, this ones working. :)
http://jsfiddle.net/nDNXc/1/
upd: Just in case jsfiddle is not responding here is the code...
CSS:
HTML:
Its a classical problem, when you scroll the modal popup generated on the screen stays at it place and does not scroll along, so the user might be blocked as he might not see the popup on his viewable screen.
The following link also provides CSS only code for generating a modal box along with its absolute position.
http://settledcuriosity.wordpress.com/2014/10/03/centering-a-popup-box-absolutely-at-the-center-of-screen/
I think you need to make the
.holder
position:relative;
and.popup
position:absolute;
It took a while to find the right combination, but this seems to center the overlay or popup content, both horizontally and vertically, without prior knowledge of the content height:
HTML:
CSS:
One solution where we need not know the width/height of the dialog and then assume the margins.
Html:
Css: