I have a div
with a height
that is set to window height by using some JS, and an image that is vertically and horizontally centered. While using max-width: 100%
on the image, I can get it to scale when the width is resized, but I want to know how to scale the image when the window is resized vertically. Any help or suggestions on how to solve this would be appreciated.
EDIT:
I'm stupid. I forgot to mention that I have texted on the bottom of the image, and when you scale vertically, the text overlaps the image. I'm trying to solve this by scaling the image vertically.
HTML:
<div class="main">
<img class="img-resp img" src="path/to/img.jpg">
<h1>Big Bold Headline</h1>
</div>
CSS
html,body { height: 100%; }
.main { background: black; position: relative; }
.img-resp { display: block; max-width: 100%; }
.img { position: absolute; top: 50%; left: 50; margin: 0 -100px 0 -100px; }
JS
var windowHeight = $(window).width();
$('.main').height(windowHeight);