Fit img in div container

phpsql

New Member
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 \[code\]img\[/code\] grow or shrink to the size of its parent \[code\]div\[/code\] 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 \[code\]div\[/code\]'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).
 
Back
Top