Saturday, 7 September 2013

Fully cover the container using a proportionally scaled image

Fully cover the container using a proportionally scaled image

I want to scale an image following these rules:
if (containerWidth/containerHeight >=imgWidth/imgHeight) --> img { width:
100% }
if (containerWidth/containerHeight < imgWidth/imgHeight) --> img { height:
100% }
The idea is to fully cover the container using a proportionally scaled
image (without javascript).
Desired result: http://jsfiddle.net/pu76s/4/

No comments:

Post a Comment