我正在尝试将我的内容 div 高度
设置为等于 window.height - (footer.height + header.height)
。我还制作了内容 overflow-y to scroll
。
这非常有效,除非 div 内的内容超过高度限制 div 拉伸(stretch)超过其高度而不是进入滚动模式,有人可以告诉我我在这里缺少什么吗?提前致谢!
$("#p_body").height($(window).height() - ($("#p_header").height() + $("#p_footer").height()) );
$("#content_body").height($("#p_body").height() - ($("#content_header").height() + 10) );
页面结构:
<div id="p_header"></div>
<div id="p_body">
<div id="content_header"></div>
<div id="content_body" style="overflow-y:scroll;"></div>
</div>
<div id="p_footer"></div>
最佳答案
我明白了,问题是我必须为我的内容 div 设置任何固定高度值,例如:
<div id="p_header"></div>
<div id="p_body">
<div id="content_header"></div>
<div id="content_body" style="overflow-y:scroll; **height:10px;**"></div>
</div>
<div id="p_footer"></div>
否则代码工作正常,直到 div 内的内容超出 window.height(),因此它不会将内容 div 高度视为固定高度。
关于jquery div 等于窗口高度随内容延伸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21867844/