繁体   English   中英

如何创建具有透明背景的引导模式

[英]how to create bootstrap modal with transparent background

我的模态有问题,它显示黑色背景而不是透明。 这可能是与 CSS 相关的问题。 注意:我在类 .fade 中更改了 Opacity:.7 但这并没有影响任何东西

  <!-- Modal -->
    <div class="modal fade" id="myModal"  style="position:fixed; top:0px; left:800px;width:600px; background:none; " role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">

          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Adding Wall</h4>
        </div>
        <div class="modal-body">
            <label>Wall Id:     </label><input type="text" id="wallNametxt"/><br>
         <label>Wall Name:</label><input type="text" id="wallNametxt1"/>

        </div>
        <div class="modal-footer">
          <input type="button" id="btn" value="Add!" name="save" class="btn btn-default"/>
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div><!--End of Modal-->

点击查看输出

更新!! 它工作得很好。 但是模态被放置在一个与页面高度相同的玻璃盒子中。 我可以将其限制为高度、宽度属性,但我更想知道原因。 点击查看输出

我可以看到Bootstrap有类.modal-backdrop ,他们将背景颜色设置为黑色,你可以使用以下代码覆盖它:

.modal-backdrop {
     background-color: rgba(0,0,0,.0001) !important;
}

嘿你需要用这段代码覆盖bootstrap css。 我尝试添加没有重要关键字的样式属性,样式不起作用用这个代替你的代码。

modal-backdrop {
  background-color: transparent !important;
}

如果您使用的是Bootstrap 4,则可以将“open modal”按钮的HTML中的属性“data-backdrop”设置为“false”。
例如<button data-backdrop="false">Open modal</button>

我能够通过覆盖组件 CSS 中的以下类来解决这个问题。 简而言之,我将背景更改为透明并移除了边框。

.modal-content {
    background-color: transparent !important;
    border: 0px !important
}

.modal-header {
    border: 0px !important
}

此处提供完整实现: https : //codesandbox.io/embed/react-bootstrap-playground-forked-hrz6x?fontsize=14&hidenavigation=1&theme=dark

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM