我已经直接从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;
}

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


当前回答

我发现:

在bootstrap 3.3.0中这是不正确的,但在bootstrap 3.3.5中这是正确的。让我们看看代码。 3.3.0:

this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
    .prependTo(this.$element)

3.3.5

  this.$backdrop = $(document.createElement('div'))
        .addClass('modal-backdrop ' + animate)
        .appendTo(this.$body)

其他回答

在我的情况下解决它,在我的样式表中添加这个:

.modal-backdrop { z - index: 0; }

带谷歌调试器,可以检查元素背景和修改属性。google的运气。

这个问题与父容器的定位有关。你可以很容易地将你的模式从这些容器中“移动”出来,然后再显示出来。下面是如何做到这一点,如果你显示你的模式使用js:

$('#myModal').appendTo("body").modal('show');

或者,如果你使用按钮启动模式,删除.modal('show');只要这样做:

$('#myModal').appendTo("body") 

这将保持所有正常的功能,允许您使用按钮显示模式。

上述建议的解决方案都不适合我,但这个技巧解决了问题:

$('#myModal').on('shown.bs.modal', function() {
   //To relate the z-index make sure backdrop and modal are siblings
   $(this).before($('.modal-backdrop'));
   //Now set z-index of modal greater than backdrop
   $(this).css("z-index", parseInt($('.modal-backdrop').css('z-index')) + 1);
}); 

我在Iphone和Ipad上使用Sharepoint 2013时遇到了类似的问题 模态引导保持z索引问题与背景。

我只是在JS上使用这个:

$ (' # myModal ')。(“shown.bs。Modal ', function() { //要关联z-index,确保背景和模态是兄弟 (这).before美元($ (' .modal-backdrop ')); //现在设置modal的z-index大于background (美元). css(“z - index方法($ (' .modal-backdrop ') . css (z - index)) + 1); });

在我的例子中,原因是boostrap.min.css。当我将它作为参考从HTML文件中排除后,对话框显示在模态阴影前面。