bootstrap 打開多層模態框的情況下,關閉任意一個模態框,都會導致其余模態框的滾動條消失。
監測html發現,當打開模態框時,會給 body 元素加一個 modal-open 的 class,而在 bootstrap.css 中,有這樣一條 css 規則:
.modal-open .modal {overflow-x:hidden; overflow-y:auto}因為有 overflow-y:auto,所以模態框才可以滾動,而當關閉任何一個模態框時,body 元素的 css 規則 modal-open 會被移除掉,自然 overflow-y:auto 也就沒有了,所以模態框的滾動條就消失了。
解決方案是在模態框的 div 元素上加一條 style="overflow: auto",如下:
<div class="modal fade" ... style="overflow: auto">
這樣,模態框的滾動就不依賴 body 元素的 css 規則 modal-open 了。
實例
<div class="modal fade" id="myModal2" data-backdrop="static" <span style="color:#ff0000;">style="overflow:scroll"</span> popover-page-id="CS040104"> <div class="modal-dialog modal-1200"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title" id="myModalLabel">模態框(Modal)標題222</h4> </div> <div class="modal-body" >在這里添加一些文本</div> <div class="modal-footer"> <button type="button" class="btn btn-success" data-toggle="modal" target="modal" data-target="#myModal3">模態框</button> <button type="button" class="btn btn-default" data-dismiss="modal">關閉</button> <button type="button" class="btn btn-primary">提交更改</button> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal --> </div>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。
新聞熱點
疑難解答