jQuery: Horizontal + Vertical align
Função jQuery para alinhar horizontalmente e verticalmente o elemento.
jQuery.fn.center = function () {
this.css("position","absolute");
this.css({
top: '50%',
left: '50%',
margin: '-' + (this.height() / 2) + 'px 0 0 -' + (this.width() / 2) + 'px'
});
return this;
}
Exemplo:
<div id="centered_div">
<p>My div content here</p>
</div>
$('#centered_div').center()
Edit on jsFiddle: http://jsfiddle.net/rc6kS/