I am stuck in image dimension change on-screen responsiveness.
I have 4 products with images in one row. I wanted Images in square shape so I gave them the fixed height and auto width. they were looking good, but when I changed the screen dimensions/responsiveness, they ignored the fixed height and malfunctions.
Full-screen
In full screen, there is the default width assigned to each product of 25%. The images look square.
Different smaller dimensions.
In different screen dimensions, they do not follow the square shape.
What do I need?
I need them in a square shape, regardless of the screen dimensions, for example, if they were 300×300 on full screen, they should be at least 200×200 on small screen, and so on.
Is there any way we can calculate dynamically, the dimensions of images according to the the screen dimensions in CSS?
Code
/* css here */
<div class="bee-col-items" style="width:25%">
<div class="bee-product-inner" style="border: 1px">
<div class="bee-product-image" style="position:relative; height:332px; width:auto;"> <img style="object-fit:fill; width:100%; height:100%; " src="" />
</div>
</div>
</div>
I need your help regarding this. Thanks in advance.
2
Answers
Doing the aspect ratio trick with css will work for this. For a square using aspect ratio 1:1 is good. See below.
padding-top is the main one for the aspect ratio. if set to 100% it will mean that for width of a length, height will also be that length, if you change the 100% to something else, you maintain a different ratio.
You could use css grid or flex, and use aspect-ratio and object-fit to display the images as squares regardless of their size.
Here’s an example: