html - CSS - 溢出-y:滚动;不能滚动并获得> 100%的块高度
问题描述
我需要在里面制作 y 轴可滚动块left-navbar
。并且这个块的高度必须填满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
和max-height: 100vh
,.left-navbar
我认为它可以满足您的要求。虽然不确定在您的完整布局的上下文中(也许您不想使用 100vh 但那里的值不同)。重要的是你必须在某处限制高度。
推荐阅读
- php - 如何使用php读取API数据并将其插入MYSQL
- arrays - 数组返回正确的值,但稍后调用时将所有值返回为“未定义”
- backup - 在 Azure Service Fabric 的 BackRestore api 中创建备份策略引发错误“FABRIC_E_BACKUP_POLICY_DOES_NOT_EXIST”
- matlab - 在matlab中使用计量经济学工具箱存储p值
- python - 根据 DCGAN 论文,如何在表示的扁平向量之上训练 L2-SVM 分类器
- python - y 值与 pyplot 中的 xticks 不匹配
- linux - 如何在 alpine 中只安装 mongodb-org-shell 而不是 mongodb?
- f# - F# / Argu - 如何在不引发异常的情况下显示两级命令树的帮助
- python - Pandas:定期检查特定日期是否在索引中,如果没有,则将输入之前的那一天标记为某事?
- sql - 如何使用字符串/数字查找 SQL 中的每个表/列