To solve these issues I usually query the DOM with JavaScript to find out the size of the window. I then use:
document.getElementById('popup').style.top = window_height - popup_height / 2;
document.getElementById('popup').style.left = window_width - popup_width / 2;
The positioning of the popup must be set to 'absolute' in the CSS. To get height (same for width) I use:
if (document.body.clientHeight) {
window_height = document.body.clientHeight;
} else {
window_height = window.innerHeight;
}
If your div doesn't have an id you can still pass the object reference to the JavaScript function like:
<div class='popup' onmouseover='javascript:openPopup(this);'> ... </div>
And, in a nearby piece of code:
function openPopup(element) {
// Get window's height and width using the code above
element.style.top = window_height - popup_height / 2;
element.style.left = window_width - popup_width / 2;
}
That is, instead of querying the DOM to get the object by the ID, you directly pass the object to the JavaScript function.