I have a div
, the container and few other div
s inside - the layers. Visibility of layers is switched dynamically with JavaScript.
I want the container to fit its height to visible layer when switching between them, but also when we are zooming the page in or out. Generally I want to create a page that instantly loads all of its contents and chooses dynamically what is show, so maybe this can be done another way?
My approach was to put one layer on another by positioning them "absolute", but with this positioning the container doesn't fit its height any more. So I tried changing the height with JavaScript when switching layers (leaving support for zooming) but it seems not working, the height is still the same (minimal):
function selectLayer(layer_id) { var objs = document.getElementsByClassName("content-layer"); for (var i = 0; i < objs.length; i++) { if (objs[i].id == layer_id) { objs[i].style.visibility = "visible";
/* no reaction after executing line below */
objs[i].parentNode.height = objs[i].height + 20; // <---
} else { objs[i].style.visibility = "hidden"; } } } How to achieve full goal? Or at least, what's wrong with my code?
The rest of code, HTML:
... some content ... ... some content ... ... some content ...CSS:
#contents { position: relative; z-index: 100; min-height: 350px; margin-left: 120px; border-width: 8px; padding: 0 0.75em; }
.content-layer { position: absolute; visibility: hidden; }
FF 3.6