JSFiddle - React, Tailwind, and code Playground
HTML
<div style="background-image:...
CSS
div
{
background-repeat: no-repeat;
background-size: cover;
display: block;
margin-bottom: 20px;
width: 171px;
}
JavaScript
var divs = document.getElementsByTagName('div');
for(var i = 0; i < divs.length; i++)
{
var img = new Image();
img.src = divs[i].style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2');
if(img.width > 170)
{
var ratio = img.width / 171;
var height = Math.floor(img.height / ratio);
}
else
{
var height = img.height;
divs[i].style.backgroundSize = 'auto';
divs[i].style.backgroundPosition = 'center';
}
divs[i].style.height = height + 'px';
}