Skip to content

Instantly share code, notes, and snippets.

@xposedbones
Last active December 22, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xposedbones/6500167 to your computer and use it in GitHub Desktop.
Save xposedbones/6500167 to your computer and use it in GitHub Desktop.
Set every item (or their child) to the same height easily (needs jquery)
;(function($){
$.fn.setHeight = function(affectChildren){
if (typeof affectChildren === "undefined" || affectChildren===null) affectChildren = false;
var height = [];
this.each(function(){
if(affectChildren){
height = [];
$(this).children().each(function(){
height.push($(this).outerHeight());
});
$(this).children().css("min-height",Math.max.apply(null,height));
}else{
height.push($(this).outerHeight());
}
});
if(!affectChildren){
this.css("min-height",Math.max.apply(null,height));
}
};
// USAGE - Use both if you have webfonts, otherwise, just use $(TARGET).setHeight();
// $(window).load(function(){
// $(".auto-height").setHeight(true);
// });
//
// $(".auto-height").setHeight(true);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment