css - 对话框有两个滚动条,但我想要一个
问题描述
我做了一个对话框并给它一个固定的高度。我想保持这个高度,但我有两个滚动条,只有一个可以滚动。
这是我的 HTML 代码:
<div class="modal fade dialog-layout-modal-body" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true" #modal>
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content dialog-layout-modal-body">
<div class="modal-header">
<h5 class="modal-title">Add new item</h5>
<button type="button" class="close" (click)="close()" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<ng-content></ng-content>
</div>
</div>
</div>
</div>
这是css代码:
@media (min-width: 768px) {
.dialog-layout-modal-body {
overflow-y: auto;
max-height: 662px;
}
}
如何解决只留下一个滚动条但又保持对话框高度的问题?
解决方案
如果您的body
元素modal-open
在模型显示时调用了一个类,则使用下面的 css 隐藏body
的滚动条。
body.modal-open {
height: 100vh;
overflow-y: hidden;
}
100vh
使身体的高度为视口的 100%。更多细节在CSS-Tricks。
推荐阅读
- r - 使用 anaconda 创建 R 环境
- laravel - 将 laravel 变形集合转换为模型集合?
- java - Tomcat中的两种方式ssl
- java - 对于调用远程 API 的任务(超时 30 秒),理想的固定线程池大小是多少也包括 CRUD db 操作?
- amazon-web-services - 将 datacapture 编码数据更改为 csv
- python - 如何在 Matplotlib 中 Y 轴上的每个点之间选择大小?
- reactjs - 创造
在其他反应项目中使用反应 js 的小部件 - rabbitmq - setConfirmCallback 与 setReturnCallback
- javascript - 非循环图 3D Javascript
- kotlin - 传递给 when() 的参数不是模拟!正确存根的示例:doThrow(new RuntimeException()).when(mock).someMethod();