我已经直接从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') as any).remove();

其他回答

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

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

.modal-backdrop {
  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>

添加到你的样式表:

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

我在使用Angular 14时遇到了这个问题,我通过更改.modal- background解决了这个问题,from position: fixed;相对位置:相对位置;

::ng-deep.modal-backdrop {
  --bs-backdrop-zindex: 1050;
  --bs-backdrop-bg: #000;
  --bs-backdrop-opacity: 0.5;
  position: relative;
  top: 0;
  left: 0;
  z-index: var(--bs-backdrop-zindex);
  width: 100vw;
  height: 100vh;
  background-color: var(--bs-backdrop-bg);
}

我找到的最简单的解决方案,对我所有的案例都有效,就是在类似的帖子中回答:

下面就是:

.modal {
  background: rgba(0, 0, 0, 0.5); 
}
.modal-backdrop {
  display: none;
}

基本上,原来的背景没有使用。相反,你使用情态动词作为背景。结果是它的外观和行为与原始版本完全一致。它避免了z索引的所有问题(对我来说,将z索引改为0解决了这个问题,但创建了一个新的问题,我的导航菜单介于模式和背景之间),而且很简单。

感谢@Jevin O. Sewaruth发布的原始答案。