Reputation: 55263
I've successfully centered horizontally my overlay dialog with margin: 0 auto;.
But I have no idea how to center it vertically.
Any suggestions?
CSS:
/* =Overlay
-------------------------------------------------------------- */
#overlay {
display: none;
position: absolute;
left: 0px;
top: 0px;
width:100%;
height:100%;
text-align:center;
z-index: 1000;
}
#overlay #dish-popup {
margin: 0 auto;
background-color: #fff;
padding:15px;
text-align:center;
width: 810px !important;
height: 700px !important;
}
Upvotes: 2
Views: 5359
Reputation:
You can figure out vertical offset with jQuery and set it when page is loaded:
$(document).ready(function(){
var top = ($("body").height() / 2) - ($("#dish-popup").height()/2);
var left = ($("body").width() / 2) - ($("#dish-popup").width()/2);
$("#dish-popup").offset({top: top, left: left});
});
Upvotes: 1
Reputation: 10619
There are a lots of methods to achieve CSS vertical centering depending on your layouts(divs or tables). I would suggest you look here
Upvotes: 2
Reputation: 343
You need to add the rule 100% for every parent in your html structure for this to work, if all parents do not have a height of 100% then it would not center vertically on any screen.
Upvotes: 1