How to change background Opacity when bootstrap modal is open

后端 未结 14 1922
慢半拍i
慢半拍i 2020-12-24 00:37

I am using bootstrap modal. When modal is open background content opacity is not changed by default. I tried changing in js using

function showModal() {
doc         


        
相关标签:
14条回答
  • 2020-12-24 01:16

    you can set the opacity by the last parameter of rgb function.

    the opacity is 0.5 in the example

    .modal-backdrop {
        background-color: rgb(0, 0, 0, 0.5);
    }
    
    0 讨论(0)
  • 2020-12-24 01:18

    use this code

    $("#your_modal_id").on("shown.bs.modal", function(){
          $('.modal-backdrop.in').css('opacity', '0.9');
    });

    0 讨论(0)
  • 2020-12-24 01:22

    You can download a custom compiled bootstrap 3, just customize the @modal-backdrop-opacity from:

    https://getbootstrap.com/docs/3.4/customize/

    Customizing bootstrap 4 requires compiling from source, overriding $modal-backdrop-bg as described in:

    https://getbootstrap.com/docs/4.4/getting-started/theming/

    In the answers to Bootstrap 4 custom build generator / download there is a NodeJS workflow for compiling Bootstrap 4 from source, alone with some non-official Bootstrap 4 customizers.

    0 讨论(0)
  • 2020-12-24 01:26

    Just in case someone is using Bootstrap 4. It seems we can no longer use .modal-backdrop.in, but must now use .modal-backdrop.show. Fade effect preserved.

    .modal-backdrop.show {
        opacity: 0.7;
    }
    
    0 讨论(0)
  • 2020-12-24 01:27

    Adding !important to .modal-backdrop will ruin the transition on bootstrap modal

    I achieved changing modal overlay background by direct edit in bootstrap.min.css. Those who are using bootstrap CSS locally (without using CDN) can change the background-color value of .modal-backdrop class.

    If you want to change bootstrap 4 modal overlay opacity find this class .modal-backdrop.show and change opacity to the value you need.

    If want to change overlay transition timing add transition to .modal-backdrop.fade class

    If want to change transition timing for modal object change transition values in .modal.fade .modal-dialog class

    0 讨论(0)
  • 2020-12-24 01:29

    It should work with:

    .modal:before{
       opacity:0.001 !important;
    }
    
    0 讨论(0)
提交回复
热议问题