title: jQuery - resizing image to fit div
body: <p>I have divs varying in height and width and wish for my images to be automatically resized to fill these divs 100%, and then of course centred.</p>
  
  <p>At the moment my images are set to width 100% and then using the jQuery below centred, but this only works for images where the height are more than the div once resized.. how would I make it 100% for both height and width and center also.. completely filling the div (even if this means stretching the image)!</p>
  
  <p>Thanks.</p>
  
  <pre><code>$('img.shelf-img').each(function(i, item) {
      var img_height = $(item).height();
      var top_margin = -(img_height / 2);
      $(item).css({
          'top': '50%',
          'margin-top': top_margin
      });
  });
  </code></pre>