[英]Div fill remaining height
I have two div
s, the one on the bottom
has content that expands the highest. 我有两个
div
, bottom
的一个具有扩展最高的内容。 The page is 100% height/width position absolute
页面
position absolute
是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>
How can i make it so the top div
convers whatever page the bottom div
is left, so if the window
is 600
height, bottom takes 400
, top takes 200
我如何做到这一点,以便顶部
div
转换底部div
剩下的任何页面,因此,如果window
的高度为600
,底部需要400
,顶部需要200
If you want to use pure CSS is there any reason to have a top div? 如果要使用纯CSS,是否有任何理由要使用顶级div?
Check This JSFiddle Demo 检查此JSFiddle演示
In this demo you can see that without a top div, you can stick a div in bottom and the parent div fill the remain space. 在此演示中,您可以看到没有顶部div时,可以将div插入底部,而父div会填充剩余空间。
HTML: 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: 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}
Update: 更新:
But if you have to create a top div that fill remain height, it think there is no a cross-browsing solution using pure CSS but you can user a simple JQuery code. 但是,如果必须创建一个填充高度保持不变的top div,它认为没有使用纯CSS的跨浏览器解决方案,但是您可以使用简单的JQuery代码。
Assume you have this HTML: 假设您有以下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>
So use this JS: 所以使用这个JS:
function setHeight() {
$(".top").height($(".page").height() - $(".bottom").height());
}
$(document).ready(setHeight);
$(window).resize(setHeight);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.