How to remove bootstrap modal overlay?
Asked Answered
R

15

32

How to remove bootstrap modal overlay for particular modal. when modal appears background has black color with some opacity is there any option for removing that elements...

Relativistic answered 8/9, 2015 at 13:37 Comment(1)
removed based on what criteria? Can you show some code?Fradin
D
53

Add data-backdrop="false" option as attribute to the button which opens the modal.

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" data-backdrop="false">
  Launch demo modal
</button>

See modal options

Dabney answered 24/2, 2017 at 9:47 Comment(1)
This has been updated in 5.3 to data-bs-backdrop="false"Ardehs
D
14

You can also set

.modal-backdrop {
   background-color: transparent;
}

in your css and bootstrap click outside function will still work.

Dominiquedominium answered 18/7, 2017 at 11:1 Comment(1)
Absolutely Brilliant.! Simple and sweet. Straight to the point without any fuzz.Passacaglia
R
12

I was able to use the following snippet to hide the model overlay by just re-hiding the modal when the shown.bs.modal event is triggered.

<script type="text/javascript">
  $('#modal-id').on('shown.bs.modal', function () {
      $(".modal-backdrop.in").hide();
   })
</script>
Relativistic answered 9/9, 2015 at 9:33 Comment(0)
A
11

You can also do it this way if you trigger you modal from javascript, add the data-backdrop="false" to the modal directly Example Below:

 <div class="modal fade" id="notifyModal" data-backdrop="false"
tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content" id="info_content">
            A Project has been deleted successfully!
        </div>
    </div>
</div>
Arcadia answered 2/2, 2020 at 20:29 Comment(1)
This has been updated in 5.3 to data-bs-backdrop="false"Ardehs
S
7

If you are dealing with bootstrap modal through jquery then better you use below code in your event callback function.

$('.modal-backdrop').remove();
Strobile answered 7/12, 2018 at 14:11 Comment(0)
A
3

If you using function click in javascript (jquery). You using :

$("#myBtn2").click(function(){
    $("#myModal2").modal({backdrop: false});
});
Allies answered 8/12, 2018 at 8:41 Comment(0)
H
2

The background is fired with the following class: .modal-backdrop with an additional .in class for opacity.

Default values (edit as needed):

.modal-backdrop {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1040;
    background-color: #000;
}
.modal-backdrop.in {
    filter: alpha(opacity=50);
    opacity: .5;
}
Haul answered 8/9, 2015 at 13:44 Comment(2)
@Manigandaprabhu: #modal-id .modal-backdrop { ... }Bilbo
in the given example, change opacity: .5; to opacity: .0;Suetonius
H
0
$("#myModal").on('hide.bs.modal', function(){
    $('.modal-backdrop').remove()
});

This should work as a charm

Hypermeter answered 2/6, 2020 at 7:59 Comment(0)
O
0

This works for me. You may try this.

$('.close').click();

$(document.body).removeClass("modal-open");

$("modal-backdrop").remove();

https://github.com/valor-software/ngx-bootstrap/issues/853

Orv answered 11/5, 2021 at 5:33 Comment(0)
P
0

  <script>
    $(document).ready(function(){
  $("button").click(function(){
    $("div").removeClass("modal-backdrop");
  });
});
    </script>
Polka answered 21/9, 2021 at 10:45 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewMeleager
S
0

You can use backdropClass, a custom class to append to the modal backdrop (api).

TS

this.modalService.open(MyModalComponent, {
      backdrop: 'static',
      keyboard: false,
      backdropClass: 'no-backdrop'
});

CSS (global style)

.no-backdrop {
  background: transparent;
}
Suctorial answered 23/3, 2022 at 14:47 Comment(0)
R
0

I had this issue and i solved it by removing the div with class modal-backdrop. after the ajax success.

$.ajax({
         url: 'Your/URL',
         type: 'POST',
         data: formData, // Instance of FormData()
         contentType: false,
         processData: false,
         headers: {
             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                   },
         success: function(response) {
              $('.modal-backdrop').remove()
              // Your code here, what you wanna do after the success of your ajax call
                  },
         error: function() {
               console.log('error');
                   },
         complete: function() {
                console.log('complete');
                   }
        })

I'm using : Bootstrap "version": "4.0.5".

Radicalism answered 15/6, 2022 at 9:36 Comment(0)
T
0

I had the same problem and found out that ii I simply used javascript to show and hide the modal form and remove the data-target attribute from the button that calls the modal, everything works fine. No need to remove data-backdrop and all of that stuff.

Tiffanitiffanie answered 19/7, 2022 at 8:36 Comment(0)
A
0

Add data-bs-backdrop="false" to modal attributes not the button that triggers the modal.

https://getbootstrap.com/docs/4.0/components/modal/

Aa answered 5/4, 2023 at 14:42 Comment(0)
E
0

Bootstrap 5.2.3

HTML:

<div id="mobile-menu" class="modal fade" aria-labelledby="menuModalLabel" aria-hidden="true" tabindex="-1">
   ....
</div>

JS:

const menuModal = new bootstrap.Modal('#mobile-menu', {
  backdrop: false
});
//show modal:
$(".book").on('click', function(e){
    e.preventDefault();
    menuModal.show();
});

CSS:

if you need only high opacity to backdrop apply this:

.modal-backdrop.show {
    --bs-backdrop-opacity: .1;
}
Eaddy answered 12/11, 2023 at 12:0 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.