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

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


当前回答

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

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

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

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

其他回答

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

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

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

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

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

但是迟了,这里有一个通用的解决方案

    var checkeventcount = 1,prevTarget;
    $('.modal').on('show.bs.modal', function (e) {
        if(typeof prevTarget == 'undefined' || (checkeventcount==1 && e.target!=prevTarget))
        {  
          prevTarget = e.target;
          checkeventcount++;
          e.preventDefault();
          $(e.target).appendTo('body').modal('show');
        }
        else if(e.target==prevTarget && checkeventcount==2)
        {
          checkeventcount--;
        }
     });

访问这个链接-当使用固定的侧边栏时,引导3模式在背景下消失。

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

在附加到主体时要小心!

这肯定会从背景后面得到那个模态:

$('#myModal').appendTo("body").modal('show');

然而,这将在每次打开主体时添加另一个模态,这可能会导致在更新面板中添加具有编辑和更新的网格视图等控件到模态时头痛。因此,你可以考虑在模式关闭时删除它:

例如:

$(document).on('hidden.bs.modal', function () {
        $('.modal').remove();
    });

将删除添加的模态。(当然,这是一个例子,你可能想要使用另一个你添加到模态的类名)。

正如其他人已经说过的;你可以简单地从模式中关闭back-drop (data- background ="false"),或者如果你不能没有屏幕变暗,你可以调整.modal- backstage CSS类(或者增加z-index)。