I have a long page built using Angular. The images on the page are lazy loaded, so src not set until the image scrolls.
The container is flexible, and images should never scale more than their sizes (which I know and can set the style attribute)
Now I have problems getting images without properly scaling the source.
TL DR I want <img src='pic.jpg'/> and <img src=''/> occupy the same amount of space inside a flexible container with maximum dimensions.
DEMO: http://codepen.io/chrismbarr/pen/xGgGRq?editors=110
HTML (this will be created from JavaScript, where we know the sizes before)
<div class="container" style='max-width: 500px; max-height: 700px;'> Image with a source <img src="http://lorempixel.com/500/700/cats/2/" /> </div> <div class="container" style='max-width: 500px; max-height: 700px;'> Image with no source <img src="" /> </div>
CSS
img{ display:block; max-width: 100%; } img[src=''], img:not([src]){ //no image source height: 100%; width: 100%; }
Here, the demonstration of image sizes is hardcoded, so they are no longer flexible. I want to avoid this: http://codepen.io/chrismbarr/pen/JdEYMe
source share