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

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


当前回答

我删除了模态背景。

.modal-backdrop {
    display:none;
}

这不是更好的解决方案,但对我来说是可行的。

其他回答

另外,确保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>

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

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

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

.modal {
    z-index: 1101;
}

在你的情态动词中使用:

data-backdrop="false" 

我有一个更轻更好的解决方案。

它可以很容易地解决通过一些额外的CSS样式..

隐藏类.modal- background(从Bootstrap.js自动生成) .modal-backdrop { 显示:没有; 可见性:隐藏; 位置:相对 } 将.modal的背景设置为半透明的黑色背景图像。 .modal { 背景:url(“http://bin.smwcentral.net/u/11361/BlackTransparentBackground.png”) //来自谷歌图像的半透明图像 z - index: 1100; }

如果你有一个需求,需要模态在元素内部,而不是在</body>标签附近,这将是最好的工作。