Forum Moderators: open

Message Too Old, No Replies

Dynamically changing height

making 2 divs the same height

         

thesheep

1:40 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Can't believe how complicated messing around with heights seems to be.

I'm looking for a W3C-compliant way of checking the height of a div and resizing it if it is shorter than another div.

function checkHeight() {
var c1 = document.getElementById("c1");
var c2 = document.getElementById("c2");

if(c1.offsetHeight < c2.offsetHeight){
c1.style.height = c2.offsetHeight;
}
}

Something along these lines. I've tried using offsetHeight, clientHeight, style.pixelHeight, all these kind of things.

What I'd really like to know is what is a standards-compliant way of doing this. Failing that, just something that works (nothing has yet). Thanks.

thesheep

2:26 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



I should maybe add that c2 is absolutely positioned and contained inside c1

thesheep

2:53 pm on Nov 15, 2005 (gmt 0)

10+ Year Member



Ah ha! style.height should be a string, offsetHeight is an int.

gawotn

5:01 am on Nov 16, 2005 (gmt 0)

10+ Year Member



Try this:
[projectseven.com...]
It helps with 2 columns being equal height, depending upon the other.
Not sure what you're trying to do, but this may help.