Dynamically changing the height of a div [duplicate]
Possible Duplicate:
Height of a div
Hello,
I have a DIV where I want the height to be based on the viewable area of the browser - 100px. Is there a way that I can make this happen so that the DIV height is set correctly in the first place and then adjusted if the user goes in and resizes the browser. I imagine this would involve javascript.
Thanks,
CSS only solution:
.foo {
position: absolute;
left: 50px;
top: 50px;
right: 50px;
bottom: 50px;
background-color: lime;
}
Demo here
There is a post on net Change DIV height/width with body width/height using jQuery
<script language=”javascript”>
$(document).ready(function(){
var height1 = $(document).height(); // height of full document
var height2 = $(“#header”).height(); // height of header
var height_diff = height1 – height2 + “px”;
document.getElementById(‘test’).style.height = height_diff; // Set the remaining height in test DIV.
});
</script>
where test
is the div
's id.
精彩评论