$(function() { // vertical 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); }); }; $('.greenBorder img').vAlign(); // });
<div class="greenBorder"> <img src="http://gawebdev.com/georgia-web-development/wp-content/uploads/2012/12/page_css_128.png?f35187" alt="" title="" border="0" /> </div>
.greenBorder{ border: 1px solid green; height: 278px; width: 446px; text-align:center; }