简体   繁体   English

如何使此溢出div扩展为填满页面高度?

[英]How can I make this overflow div expand to fill up page height?

Here's an example that goes halfway there: http://jsfiddle.net/gt9vz4qk/1/ 这是一个示例,其中包括: http : //jsfiddle.net/gt9vz4qk/1/

CSS: #content {background-color: #fdd; overflow: auto; height: 70vh;} CSS: #content {background-color: #fdd; overflow: auto; height: 70vh;} #content {background-color: #fdd; overflow: auto; height: 70vh;}

HTML: HTML:

<button>Hello</button>
<div id="content">
A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>
A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>
A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>
</div>
<input>

Using relative size units like vh helps, but I feel like I'm missing something really basic. 使用像vh这样的相对大小单位会有所帮助,但是我感觉好像缺少了一些非常基本的东西。 As you can see, if you resize the window or even the splitter on the jsfiddle website far down, the other elements start compressing and a second scrollbar pops up. 如您所见,如果您在jsfiddle网站上调整窗口或什至拆分器的大小,则其他元素将开始压缩,并弹出另一个滚动条。 The only scrollbar should be the overflow one. 唯一的滚动条应该是溢出的。

Another way to think about this is that I want the top elements to take up as much space as they need, the bottom elements to take as much space as they need, and anything else should be taken up by the central element. 考虑这种情况的另一种方法是,我希望顶部元素占用所需的空间,底部元素占用所需的空间,而其他任何内容都应由中央元素占用。

Here's a flexbox solution: 这是一个flexbox解决方案:

 html, body { height: 100%; margin: 0; } body { display: flex; flex-direction: column; } #content { background-color: #fdd; overflow: auto; flex: 1; } 
 <div> <button>Hello</button> </div> <div id="content"> A<br> A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br>A<br> </div> <div> <input> </div> 

Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM