【问题标题】:Scrollbar is disabled when Bootstrap modal is openedBootstrap 模式打开时滚动条被禁用
【发布时间】:2017-02-10 00:52:27
【问题描述】:

我使用以下代码使页面的滚动条始终可见:

html {
    overflow-y: scroll; 
}

但是,当打开 Bootstrap 模式时,主滚动条不可用(可见但已禁用),并且在尝试如下所示的某些代码时无法解决问题。

.modal-open {    
    overflow-y: scroll !important; 
}

我想尝试以下方法:

1) 即使模式打开,我也希望启用主滚动条

2) 我希望模态的滚动条是自动可见的,但是当我使用overflow-y:scroll;模态体的高度无法自动增加,并且模态内容上的滚动条似乎被禁用(当我设置高度时,滚动条被启用,但我想使用自动高度)。有什么想法吗?

【问题讨论】:

  • 请粘贴一些代码。

标签: html css twitter-bootstrap twitter-bootstrap-3 scrollbar


【解决方案1】:

尝试改变这一行:

.modal-open {    
   overflow-y: scroll !important; 
}

到:

body.modal-open {
  overflow: scroll; !important;
}

sn-p:

body.modal-open {
  overflow: scroll; !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-sm">Small modal
</button>

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">
                This is the modal
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div style="height: 1600px;"></div>

【讨论】:

  • 我遇到了同样的问题,但不幸的是,这种方法对我没有帮助。见itc-ms.de。当模式对话框打开时,主体页面仍然会随着主滚动条的消失而移动。
  • @MichaSchumann 我一添加样式 body.modal-open {overflow: scroll; !important;} 在你的标题中它工作得很好。告诉我
  • 2021 年仍然在摆弄 BS3(叹息......)。无论如何,如果你没有注意到这个例子中有一个错字 - 应该是: body.modal-open { overflow-y: scroll !important; }(滚动后没有分号)
  • 抱歉错误。我的错。无论如何,您可以添加小提琴以创建证据吗?谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-10
  • 1970-01-01
  • 2023-03-22
  • 2019-07-14
  • 2015-07-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多