Div填充剩余高度
Div fill remaining height
我有两个div
,bottom
上的一个内容扩展得最高。页面为100%高/宽position absolute
<style>
body, html { height:100%, width:100% }
.page { position: absolute; height: 100%; top: 0; right: 0; left: 0; bottom: 0}
.bottom { position absolute; bottom: 0; right: 0; left: 0; }
.top { position absolute; bottom: 0; right: 0; left: 0; }
</style>
我怎么能让顶部的div
转换底部的div
剩下的任何页面,所以如果window
是600
高度,底部取400
,顶部取200
如果你想使用纯CSS,有什么理由拥有顶级div吗?
检查此JSFiddle演示
在这个演示中,您可以看到,如果没有顶部div,您可以在底部粘贴一个div,父div填充剩余的空间。
HTML:
<div class="page">
this is top
<div class="bottom">
This is a text
<br/>
In order to expand the bottom
<br />
blah blah
<br />
blah blah blah
<br />
blah blah blah blah
</div>
</div>
CSS:
body, html { height:100%, width:100% }
.page { position: absolute; height: 100%; top: 0; right: 0; left: 0; bottom: 0; background-color:green}
.bottom { position: absolute; bottom: 0; right: 0; left: 0; background-color:red}
更新:
但是,如果你必须创建一个填充剩余高度的顶部div,它认为没有使用纯CSS的交叉浏览解决方案,但你可以使用一个简单的JQuery代码。
假设你有这个HTML:
<div class="page">
<div class="top">
this is top
</div>
<div class="bottom">
This is a text
<br/>
In order to expand the bottom
<br />
blah blah
<br />
blah blah blah
<br />
blah blah blah blah
</div>
</div>
所以使用这个JS:
function setHeight() {
$(".top").height($(".page").height() - $(".bottom").height());
}
$(document).ready(setHeight);
$(window).resize(setHeight);
检查JSFiddle演示
相关文章:
- electronic BrowserWindow的最小高度和宽度在hide()show()方法之后不起作用
- ExtJS——在展开/折叠时调整面板高度
- 分析高度属性时出现意外值{{specs.height}}.index.html
- 单击页面上的链接后高度发生变化
- 不加载宽度和高度的角度pintura
- 查找元素高度,包括边距
- 如何自动调整标签的高度以适应内容
- Javascript高度问题
- 使用JavaScript根据窗口/视口的高度动态调整图像大小
- 如何计算每个元素's的高度,并将这些值用作函数中的变量
- 如果宽度是百分比,如何设置以px为单位的图像高度
- 通过jquery设置最小高度
- 文档就绪提供了错误的选择器高度
- 调整缩放窗口高度提升缩放
- 根据图像高度添加类
- 检测非移动页面上的移动设备屏幕宽度和高度
- 根据页眉和页脚高度更改高度的动态内容
- 根据 jQuery 中多个实例上的另一个元素高度设置高度
- ajax表单提交后iScroll4高度错误.高度是表单提交前的原始高度
- 最小高度、高度、类别、id优先级