Last Updated: February 25, 2016
·
2.698K
· tompntn

jQuery - CSS Automatic margin-top

Finds every instance of the specific class, and sets the margin-top to be a negative value of the height.

<br>

Useful for image gallery captions


$(".YOURCLASS").each(function(){
$(this).css("margin-top","-"+$(this).height()+"px");
});