37
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 browser.
What am I doing wrong?
$(document).ready(function (){
$(window).resize(function (){
$('.className').css({
position:'absolute',
left: ($(window).width() - $('.className').outerWidth())/2,
top: ($(window).height() - $('.className').outerHeight())/2
});
});
$(window).resize();
});