Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery Vertically Center Content Re: jQuery Vertically Center Content

#103173
Taufik Nurrohman
Participant
$(document).ready( function() {
var $img = $('img');
$img.css({
'display': 'block',
'position': 'absolute',
'top': $(window).height()/2,
'left': $(window).width()/2,
'margin-left': '-' + ($img.width() / 2) + 'px',
'margin-top': '-' + ($img.height() / 2) + 'px'
});
});

Edit: I just missed the quotes