var wid = $('#container').width(); var hei = $('#container').height(); $('#container').css({ 'margin-left':wid/2*(-1), 'margin-top':hei/2*(-1)}); });