A very basic solution (assuming that the height is always half the width (400x200))
HTML Code:
dv = document.getElementById("MyDiv")
dv.style.height = dv.offsetWidth / 2 +"px"
where "MyDiv" is the id of the div you want to resize.
The problem with this is that resizing the window, the height will stay the same when the width changes.
To Solve that, put the above code in a function :
HTML Code:
function Resize()
{
dv = document.getElementById("MyDiv")
dv.style.height = dv.offsetWidth / 2 +"px"
}
and put the following in the body tag of your page :
HTML Code:
<body onresize="Resize()" onload="Resize()">
Which tells the document to call Resize() every time the window is re-sized.
This works in both IE and FF, haven't tried in other browsers.
Bookmarks