CreateSean
CreateSean

Reputation: 1386

Set element height equal to body height minus 170px

I've got a div that is absolutely positioned in the bottom right corner of the page. The problem is that if the div contains too much content then the top of the content disappears under top of the page. What I want to do is set the max-height of the div to be equal to the body height minus 170px.

I've tried a couple of tutorials online but didn't get very far:

What Iv'e got so far is:

<script>
var x, y, z;
y = 170;
function getDocHeight() {
    var x = document;
    return Math.max(
        Math.max(x.body.scrollHeight, x.documentElement.scrollHeight),
        Math.max(x.body.offsetHeight, x.documentElement.offsetHeight),
        Math.max(x.body.clientHeight, x.documentElement.clientHeight)
    );
};
z = x-y;//document height minus 170. this is the height we need for the info div
document.write (z);
document.write (y);
document.write (x);
</script>

What the above outputs is NaN170undefined so I haven't even gotten to trying to set the height of the div id="info"

All help is greatly appreciated.

Sean

Upvotes: 1

Views: 1086

Answers (1)

Mathew Thompson
Mathew Thompson

Reputation: 56459

If you are using JQuery, you could do the following:

z = $("body").height() - 170;

Upvotes: 1

Related Questions