I have a repeater with an image. I want the image to fit in a box of 187x180px but maintaining whatever aspect ratio it happens to have (so it doesn’t need to cover 187x180px, just needs to fit within). Here’s my code:
let url = SOME_URL
$item('#htmlProfilePicture').html = `
<img id="img"
class="filterPhoto"
src="${url}"
alt="profilePhoto"
style="object-fit:contain;height:180px;width:187px"
>`;
(by they way, $item(‘#htmlProfilePicture’) is a text element)
It works fine apart from the fact that object-fit:contain
is ignored. So when I inspect the source on my preview version of the page I get the height and width style params, but the object-fit is not there.
Inserting object-fit:contain
into the developer tools of my browser yields the effect I’m looking for.
May be worth noting that I also tried putting the style in the header via the analytics and tracking section of the settings for the site. Like so:
<style>
img.filterPhoto {
object-fit: contain;
}
</style>
But that didn’t help either.