我已经直接从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上添加id“my-modal”的“modal”类,由$('#my-modal').modal('show')提升;

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

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

其他回答

添加到你的样式表:

.modal-backdrop {
    background-color: #000;
    bottom: 0;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 0 !important;
}

另外,确保BootStrap的css和js版本是相同的。不同版本也可以使模态出现在背景下:

例如:

Bad:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>

好:

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

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

将绝对位置更改为相对位置。

.modal-backdrop {
    position: relative;
    /* ... */
}

将z-index .modal设置为最高值

例如, .sidebarwrapper的z-index为1100,因此将.modal的z-index设置为1101

.modal {
    z-index: 1101;
}