Is there a way to ensure that all images maintain the same height and width using CSS percentages, rather than set pixel values? I'm working on displaying images in circles, where most are uniform in size but a few outliers distort the shape. The wide images fit properly, but the tall ones appear oval-shaped.
https://i.sstatic.net/GZry6.png
I'm not concerned about adjusting the wide images as they already fit within the circle. However, the issue lies with the taller images that need to be corrected.
A snippet of the HTML (JavaScript -- Google Maps API InfoWindow)
for (i = 0; i < myList[infoId].numOfFUnits; i++) {
infoString = infoString + ("<a href=\"" + myList[infoId].fUnits[i].pageLink + "\"><img src=\"" +
myList[infoId].f[i].photo + "\" class=\"mPhoto\" alt=\"" + myList[infoId].fUnits[i].displayName + "\"></a>");
}
infoString = infoString + ("<br/><strong>Images</strong></div>");
var infoBox = new google.maps.InfoWindow({
content: infoString,
});
CSS
.mPhoto{
margin-top: 5px;
width: 30%;
height: auto;
border-radius: 50%;
border: 1px solid white;
}
- One solution I've tried is setting max-height to 188.09px (equal to full screen width), but this causes issues when the window is resized smaller.
- Since the HTML is within JavaScript, I can't use
to adjust the max-height based on current width.document.getElementsByClassName().style
- Attempts to use background images require specific pixel dimensions instead of percentages.
- Changing object-fit didn't have the desired effect, despite initial appearances.
Do you have any suggestions?