I am using this script to center my div horizontally and vertically.
When the page loads the div gets centered vertically, not horizontally until I resize the brows
based on @dimi's answer, works better with multiple elements
$(".className").each(
function () {
$( this ).css("position","absolute");
$( this ).css("left","50%");
$( this ).css("margin-left", - $( this ).outerWidth()/2 );
$( this ).css("top","50%");
$( this ).css("margin-top", - $( this ).outerHeight()/2 );
return this;
}
);