What is the best way to simulate upcoming CSS3 object-fit property using CSS2 & JS? I'm interested in contain & cover methods for fitting.
EDIT: In CSS3 there is the new object-fit mechanism described here: http://dev.opera.com/articles/view/css3-object-fit-object-position/ but object-fit is not yet supported outside the Opera browsers. To create a portable solution I need to make an img
grow or shrink to the size of its parent div
without loosing the original aspect ratio of the image. This can be achieved by either containing the whole image (technique also called letterboxing) or by enlarging & overflowing the image until the smallest dimension matches the div
's dimension (technique also called as cover). There are a few jquery imagefit libraries out there by they are very buggy (perhaps they work only in a specific situation on a specific browser).
EDIT 2: This question has been understood by those taking the time to read it, a good answer has been suggested and an answer has been given. It is difficult to understand the decision of closing it.