Forums

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

Home Forums CSS CSS Centering Images help Re: CSS Centering Images help

#103160
chrisburton
Participant

@joshuanhibbert Thanks. Too bad I need a jQuery solution.

I found this

jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", (($(window).height() - this.outerHeight()) / 2) +
$(window).scrollTop() + "px");
this.css("left", (($(window).width() - this.outerWidth()) / 2) +
$(window).scrollLeft() + "px");
return this;
}

// Now we can just write:

$(element).center();

Solved: Result