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

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


当前回答

这种行为有时发生在有未关闭标记时,尤其是未关闭</div>。你可以检查你的模式的位置,确保所有的标签都是正确关闭的,或者更好的是将div模式移动到页面底部,在</body>标签框之前

其他回答

在我的情况下,解决方案是简单的,我忘记在div上添加id“my-modal”的“modal”类,由$('#my-modal').modal('show')提升;

因为div的内容包含了所有需要的内容,所以除了上面的覆盖之外,屏幕上的结果几乎是完美的。

我敢打赌,其他与z-index技巧或其他css技巧无关的父div或未关闭div的位置的答案也可能是在这种情况下。

我简单地设置了:

#myModal {
    z-index: 1500;
}

它工作....

对于原来的问题:

.my-module {
    z-index: 1500;
}

另一种方法是从bootstrap.css中的.modal- background中删除z-index。这将导致背景与身体的其他部分在同一水平线上(它仍然会褪色),你的模态在顶部。

.modal- background是这样的

.modal-backdrop {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: #000000;
}

我在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); });

我尝试了上面提供的所有选项,但没有得到它的工作使用这些。

什么是有效的:设置。modal- background的z-index为-1。

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