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

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


当前回答

对我来说,最简单的解决方案是把我的模态放在一个绝对位置和z索引高于.modal- background的包装器中。因为模态背景(至少在我的情况下)的z指数为1050:

.my-modal-wrapper { 位置:绝对的; z - index: 1060; } < div class = " my-modal-wrapper " > < / div >

其他回答

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

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

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

在你的导航栏navbar-fixed-top需要z-index = 1041 如果你使用bootstarp-combined.min.css,也需要将。navbar-fixed-top, .navbar-fixed-bottom z-index改为1041

.modal-backdrop {
/* bug fix - no overlay */    
display: none;}

我发现通过添加内联样式标签来设置“display: none”可以防止这个问题。代码的位置没有任何影响。