Skip to content

Instantly share code, notes, and snippets.

@ivandoric
Created April 23, 2014 15:10
Show Gist options
  • Save ivandoric/11219200 to your computer and use it in GitHub Desktop.
Save ivandoric/11219200 to your computer and use it in GitHub Desktop.
jQuery: Vertical align elements
(function (jQuery) {
// VERTICALLY ALIGN FUNCTION
jQuery.fn.vAlign = function() {
return this.each(function(i){
var ah = jQuery(this).height();
var ph = jQuery(this).parent().height();
var mh = Math.ceil((ph-ah) / 2);
jQuery(this).css('padding-top', mh);
});
};
})(jQuery);
jQuery('.main-menu a').vAlign();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment