Well, I suggest using a lightweight jQuery plugin that is flexible for all your needs. Here is an example:
(function ($) { // VERTICALLY ALIGN FUNCTION $.fn.vAlign = function() { return this.each(function(i){ var ah = $(this).height(); var ph = $(this).parent().height(); var mh = Math.ceil((ph-ah) / 2); $(this).css('margin-top', mh); }); }; })(jQuery);
Then you just use the function on the selector you want:
$('#example p').vAlign();
Malyo source share