开发者

Dynamically changing the height of a div [duplicate]

This question already has answers here: Closed 11 years ago. 开发者_如何学编程

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜