1
With the example below we calculate the Aspect ratio of an image by setting Width/Height manually, with this the value of the Aspect ratio is generated to be put in the padding-bottom:
What I would like is something similar: I want to take the widht/height value of an image, calculate the ratio value, and put it in its container, all automatically. There will be several images with different dimensions.
<div class="image-container">
<img src="minhaimagen.jpg" width="300" height="200">
</div>
The generated value would be in a padding-bottom
in the div image-container
Example: https://codepen.io/EightArmsHQ/full/OMGOyE/
For some reason you can’t put the example here in Stack.
Link you might be interested in https://css-tricks.com/aspect-ratio-boxes/
– hugocsl
Aspect Ratio in this case would it be to make the image proportional (relative to height)? For example, an image with 320wx240h and resize it to 640 height automatically the width will be 480?
– RpgBoss
@Rpgboss I can’t say. This Aspect Ratio Generator solves the problem I was having with lazysizes. The ratio is calculated based on Width/Height, generating a value to be placed in the padding-bottom, and it works really well. I’ll just have several images with different dimensions and I don’t want to have to manually set their ratio. But do automatically as described in the question. That’s all.
– John Quimera