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

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


当前回答

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

$('#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);
}); 

其他回答

嗨,我有同样的问题,然后我意识到,当你使用bootstrap 3.1 不同于旧版本的bootstrap (2.3.2) 模态的HTML结构被改变了!

你必须用模态对话框和模态内容来包装你的模态页眉、页脚

<div class="modal hide fade">

  <div class="modal-dialog">
    <div class="modal-content">

    **here goes the modal header body and footer**

    </div>
  </div>

 </div>

在CSS中添加这些对我来说是一种技巧。

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

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

当在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文件。

和Davide Lorigliola一样,我通过提高z指数来解决这个问题:

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