I am working on a flexible design that shows photos in a grid. Photos themselves can be in all proportions and sizes. In addition, the grid cells in which they are placed also do not have a fixed width; they scale when the browser is resized. In addition, each grid cell, although dynamic in width and height, has the same size, regardless of the image inside it.
To correctly show photos in this very dynamic situation, I found a working recipe: each photo is basically a div with the image set as the background image. To correctly scale the unknown width / height of an image inside a dynamic-sized grid, I use the CSS3 background-size: cover function.
The end result is fabulous, it does exactly what I want in terms of user interface and display. However, I am not happy with the reduced availability of this solution: it is not optimized for SEO and does not support the plugin (think about social plugins). So I'm trying to reproduce the working situation that I have, but this time using the good old img tags instead of CSS backgrounds.
I know that there is IE8 and lower polyfills for background-size: cover, but I'm not looking for this, I'm looking for a solution based on img tags. I also found articles using absolute positioning methods, as well as CSS clip properties, but I donโt remember anything about the fact that my design is absolute in size.
I suppose I'm looking for a Javascript subroutine that has background size logic: a cover for dynamic measurement, in a situation where both the source (image size) and target (display field) are dynamic in size.
Is there such a javascript equivalent for the background: a cover that works with img tags?
css image css3
Ferdy
source share