JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="overlayContainer">
<div id="square">
<div></div>
</div>
</div>
CSS
html, body{
height: 100%;
overflow: hidden;
}
body{
margin: 0;
background-image: url('https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Alexanderplatz_Stadtmodell_1.jpg/1920px-Alexanderplatz_Stadtmodell_1.jpg');
background-size: contain;
background-repeat: no-repeat;
background-position: center;
}
#overlayContainer{
position: absolute;
max-width: 100vw;
max-height: 100vh;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
#square{
position: relative;
padding-bottom: 100%;
}
#square div{
position: absolute;
top: 19.75%;
left: 49.75%;
width: 4.75%;
height: 4.75%;
background-color: rgba(255,0,0,.5);
border-radius: 50%;
}
JavaScript
var image = new Image()
image.src = $('body').css('background-image').replace(/url\((['"])?(.*?)\1\)/gi, '$2').split(',')[0]
$('#overlayContainer').css({'height':100*(image.height/image.width )+'vw',
'width' :100*(image.width /image.height)+'vh'})