This blog post describes two methods of centering a div both horizontally and vertically. One uses only CSS and will work with divs that have a fixed size; the other uses jQuery and will work divs for which you do not know the size in advance.
I've duplicated the CSS and jQuery examples from the blog post's demo here:
CSS
Assuming you have a div with a class of .classname, the css below should work.
The left:50%; top:50%;
sets the top left corner of the div to the center of the screen; the margin:-75px 0 0 -135px;
moves it to the left and up by half of the width and height of the fixed-size div respectively.
.className{
width:270px;
height:150px;
position:absolute;
left:50%;
top:50%;
margin:-75px 0 0 -135px;
}
jQuery
$(document).ready(function(){
$(window).resize(function(){
$('.className').css({
position:'absolute',
left: ($(window).width() - $('.className').outerWidth())/2,
top: ($(window).height() - $('.className').outerHeight())/2
});
});
// To initially run the function:
$(window).resize();
});
Here's a demo of the techniques in practice.