I've read through How to resize an image to fit in the browser window? but it doesn't really fit my need. All there is written for the image to fill the entire browser window. But I want a container of varying height above the image. And a fixed height section below.
JavaScript can get the height of the container. I found:
var offsetHeight = document.getElementById('topsection').offsetHeight;
Andrew Beals's solution on that page looks like a start, but how to subtract the container height, and say 2em for under? I know no JavaScript, so I'd much appreciate some help.