I have an overlay image that needs to be responsive vertically and horizontally to work on desktop and mobile.
Edit: By vertically responsive, I mean it needs to stay within the window and not overflow below the bottom of the screen.
There's a element on top of the image that needs to stay in the same place, and the image must retain its aspect ratio.
I'd rather do this with pure CSS, but could use JS for browser compatibility or a simpler solution.
http://codepen.io/brooksroche/pen/mEgJmd?editors=1100
<div class="container">
<div class="img-container">
<img src="http://placehold.it/300X200">
<div class="example"></div>
</div>
</div>
.container {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
}
.img-container {
position: relative;
margin: 0 auto;
border: 1px solid red;
width: 300px;
max-width: 100%;
}
.img-container img {
display: block;
max-width: 100%;
max-height: 100%;
}
.example {
position: absolute;
border: 1px solid blue;
top: 40%;
left: 30%;
width: 38%;
height: 20%;
}