简体   繁体   English

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

[英]how to create bootstrap modal with transparent background

I have a problem with the modal, it shows black background instead of transparent.我的模态有问题,它显示黑色背景而不是透明。 It might be a problem related to the CSS.这可能是与 CSS 相关的问题。 Note: I changed Opacity:.7 in the class .fade but that didn't affect anything注意:我在类 .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-->

Click to see the Output点击查看输出

Update!!更新!! It worked perfectly.它工作得很好。 But the modal is being placed in a glass box with the same height of the page.但是模态被放置在一个与页面高度相同的玻璃盒子中。 I can limit that to the height, width properties, but I would prefer to know the reason.我可以将其限制为高度、宽度属性,但我更想知道原因。 Click to see output点击查看输出

As I can see Bootstrap have the class .modal-backdrop and they are setting the background color to black, you can overwrite this with this code: 我可以看到Bootstrap有类.modal-backdrop ,他们将背景颜色设置为黑色,你可以使用以下代码覆盖它:

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

Hey You need to override the bootstrap css with this code. 嘿你需要用这段代码覆盖bootstrap css。 I you try to add style property without important keyword the style not work replace your code with this. 我尝试添加没有重要关键字的样式属性,样式不起作用用这个代替你的代码。

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

if you are using Bootstrap 4, you could just set the attribute "data-backdrop" in the HTML of the "open modal" button to "false". 如果您使用的是Bootstrap 4,则可以将“open modal”按钮的HTML中的属性“data-backdrop”设置为“false”。
eg <button data-backdrop="false">Open modal</button> 例如<button data-backdrop="false">Open modal</button>

I was able to solve this issue by overriding the following classes in my component CSS.我能够通过覆盖组件 CSS 中的以下类来解决这个问题。 In brief, I changed the background to transparent and removed borders.简而言之,我将背景更改为透明并移除了边框。

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

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

Complete implementation available here: https://codesandbox.io/embed/react-bootstrap-playground-forked-hrz6x?fontsize=14&hidenavigation=1&theme=dark此处提供完整实现: 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