我已经直接从Bootstrap示例中使用了我的模态代码,并且只包括Bootstrap .js(而不是Bootstrap -modal.js)。但是,我的模态出现在灰色渐隐(背景)下面,是不可编辑的。

这是它的样子:

这是重现这个问题的一种方法。该代码的基本结构是这样的:

<body>
    <p>Lorem ipsum dolor sit amet.</p>    

    <div class="my-module">
        This container contains the modal code.
        <div class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">Modal</div>
                </div>
            </div>
        </div>
    </div>
</body>
body {
    padding-top: 50px;
}

.my-module {
    position: fixed;
    top: 0;
    left: 0;
}

你知道为什么会这样吗或者我能做些什么来弥补吗?


当前回答

这招对我很管用:

sass: 
  .modal-backdrop
    display: none
  #yourModal.modal.fade.in
    background: rgba(0, 0, 0, 0.5)

其他回答

尝试将类.modal-open overflow值从隐藏重写为可见:

.modal-open {
    overflow: visible;
}

我浏览了我的HTML,发现我有一个未关闭的<div>标签。关闭<div>为我解决了这个问题。 PS: <div>标签既不是模态的祖先也不是子。

我有这个问题,最简单的解决方法是在modal-dialog div上添加z-index大于1040:

<div class="modal-dialog" style="z-index: 1100;">

我相信bootstrap创建了一个div模态背景淡出,在我的情况下,z指数为1040,所以如果你把模态对话框放在上面,它应该不再是灰色的。

我只是从_modal中删除了position: fixed样式。SCSS文件,它似乎为我工作良好。我仍然有背景和它的工作预期。

// Modal background
.modal-backdrop {
  /* commented out position: fixed - bug fix */
  //position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: $zindex-modal-backdrop;
  background-color: $modal-backdrop-bg;
  // Fade for backdrop
  &.fade {
    opacity: 0;
  }

向Rick Strahl在“引导模式对话框显示在模式背景下”中的指导致敬。

@Muhd提供的解决方案是最好的方法。但如果你陷入了无法更改页面结构的情况,可以使用以下技巧:

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="false" style="background-color: rgba(0, 0, 0, 0.5);">
<div class="modal-dialog" 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">...</div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
        </div>
    </div>
</div>

这里的技巧是data- background ="false" style="background-color: rgba(0, 0, 0, 0.5);"通过删除默认背景并通过设置对话框本身的背景色来创建一个虚拟背景。

更新1: 正如@Gustyn指出的那样,点击背景并不能像预期的那样关闭对话框。为了实现这个,你必须添加一些java脚本代码。这里有一些例子,你可以实现这一点。

$('.modal').click(function(event){
    $(event.target).modal('hide');
});