【发布时间】:2021-01-02 03:00:17
【问题描述】:
我需要在left-navbar 内制作 y 轴可滚动块。该块的高度必须填满left-navbar 的所有空闲空间。这样,left-navbar 的高度就是页面的 100%,仅此而已。
但是history-overflow是不可滚动的,所有history-item元素都显示出来了,所以他们让所有left-navbar的高度都大于页面高度。
另外,当页面高度缩小时,history-overflow 应该只填充可用空间以使left-navbar 高度不超过 100%。这个怎么做?
Codepen 沙盒示例: https://codepen.io/car1ot/pen/zYqLqKB
HTML 代码:
<div className="left-navbar">
<div className="history">
<label>History</label>
<div className="history-overflow">
<div className="history-item">*...some content here...*</div>
*...more history-item(s) here...*
</div>
</div>
</div>
CSS(scss)代码:
div.left-navbar {
display: flex;
flex-direction: column;
justify-content: space-between;
width: 290px;
height: 100%;
padding: 25px 20px;
box-sizing: border-box;
div.history {
display: flex;
flex-direction: column;
div.history-overflow {
margin-top: 8px;
margin-right: -20px;
padding-right: 14px;
overflow-y: scroll;
div.history-item {
display: flex;
align-items: center;
flex-shrink: 0;
padding: 0 16px 0 6px;
height: 40px;
width: 100%;
border-radius: 7px;
margin-bottom: 8px;
box-sizing: border-box;
}
}
}
}
【问题讨论】:
-
只是猜测,但尝试将
overflow: hidden添加到.history和.left-navbar。很难说,如果你能提供一个 jsfiddle/codepen 来重现这个问题会更容易。 -
这无济于事......