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

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


当前回答

function addclassName(){
    setTimeout(function(){
        var c = document.querySelectorAll(".modal-backdrop");
        for (var i = 0; i < c.length; i++) {
            c[i].style.zIndex =  1040 + i * 20  ;
        }
        var d = document.querySelectorAll(".modal.fade");
        for(var i = 0; i<d.length; i++){
            d[i].style.zIndex = 1050 + i * 20;
        }
    }, 10);
}

其他回答

最简单的解决方案是将模态对话框移到任何容器之外,并在<body>元素下声明它:

<body>    
    <div>
        ...
    <div>
    
    
    <div class="modal">
        ... modal dialog here
    </div>
</body>

我试过这个方法,对我很有效。

来源:https://weblog.west-wind.com/posts/2016/sep/14/bootstrap-modal-dialog-showing-under-modal-background

我删除了模态背景。

.modal-backdrop {
    display:none;
}

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

当在CSS中为背景或甚至是手风琴头使用渐变之类的东西时,经常会遇到这个问题。

不幸的是,修改或覆盖核心的Bootstrap CSS是不可取的,并且可能导致不需要的副作用。侵入性最小的方法是添加data- background ="false",但您可能会注意到渐隐效果不再像预期的那样工作。

继Bootstrap的最新版本之后,3.3.5版本似乎解决了这个问题,并且没有不必要的副作用。

下载:https://github.com/twbs/bootstrap/releases/download/v3.3.5/bootstrap-3.3.5-dist.zip。

确保包含3.3.5中的CSS文件和JavaScript文件。

根据之前的答案,这可能有几个原因。 对我来说,问题是在不知情的情况下引用两个不同的Bootstrap链接,所以删除一个就解决了问题。

在我的例子中,我包括了这个:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css"
      integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">

还有一个离线的,我的笔记本电脑里已经有了。

我也有同样的问题,也检查了Muhd的答案。

但是,我的模态需要左,顶部属性,所以只要把固定位置改为绝对,它就工作了。

.modal {
    position: absolute;
}