[英]How do I make div fill the remaining space?
假设我有这个基本的 html 布局:
标题
自动调整大小的 DIV
页脚。
页眉和页脚具有固定的像素大小。
<div id="header">
Lorem Ipsum
</div>
<div id="auto">
This div should automatically change size
</div>
</div id="footer">
Lorem Ipsum
</div>
和 CSS
document,body {
width:100%;
height:100%;
}
#header {
width:100%;
height:50px;
}
#auto {
height:100% (it fills 100% of the window height instead the remaining)
}
#footer {
width:100%;
height:50px;
}
如何让 div 填充剩余空间?
您可以通过使用 jQuery 获取窗口高度并获取窗口高度的页眉和页脚的高度并将其设置在您的 div 上来修复它。
像这样:
header {
background: red;
height: 10px;
position: fixed;
top: 0;
width:100%;
}
.resizable {
background: blue;
width: 100%;
}
footer {
background: red;
bottom: 0;
height: 10px;
position: fixed;
width:100%;
}
这是 jQuery:
$(document).ready(function(){
var newHeight = $(window).height() - 20;
$(".resizable").css("height", newHeight);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.