Bootstrap modal appearing under background

前端 未结 30 975
离开以前
离开以前 2020-11-22 17:09

I have used the code for my modal straight from the Bootstrap example, and have included only the bootstrap.js (and not bootstrap-modal.js). However, my modal is appearing u

相关标签:
30条回答
  • 2020-11-22 17:37

    I have a lighter and better solution..

    It could be easily solve through some additional CSS styles..

    1. hide the class .modal-backdrop (auto generated from Bootstrap.js)

      .modal-backdrop
      {
      display:none;
      visibility:hidden; 
      position:relative
      }
      
    2. set the background of .modal to a translucent black backdrop image.

      .modal
      {
      background:url("http://bin.smwcentral.net/u/11361/BlackTransparentBackground.png")
      // translucent image from google images 
      z-index:1100; 
      }
      

    This will works best if you have a requirement that needs the modal to be inside an element and not near the </body> tag..

    0 讨论(0)
  • 2020-11-22 17:37

    in your navbar navbar-fixed-top need z-index = 1041 and also if u use bootstarp-combined.min.css the also change .navbar-fixed-top, .navbar-fixed-bottom z-index to 1041

    0 讨论(0)
  • 2020-11-22 17:38

    I got it to work by giving a high z-index value to the modal window AFTER opening it. E.g.:

    $("#myModal").modal("show");
    $("#myModal").css("z-index", "1500");
    
    0 讨论(0)
  • 2020-11-22 17:38

    A but late on this but here is a generic solution -

        var checkeventcount = 1,prevTarget;
        $('.modal').on('show.bs.modal', function (e) {
            if(typeof prevTarget == 'undefined' || (checkeventcount==1 && e.target!=prevTarget))
            {  
              prevTarget = e.target;
              checkeventcount++;
              e.preventDefault();
              $(e.target).appendTo('body').modal('show');
            }
            else if(e.target==prevTarget && checkeventcount==2)
            {
              checkeventcount--;
            }
         });
    

    Visit this link - Bootstrap 3 - modal disappearing below backdrop when using a fixed sidebar for details.

    0 讨论(0)
  • 2020-11-22 17:38

    none of the suggested solutions above worked for me but this technique solved the issue:

    $('#myModal').on('shown.bs.modal', function() {
       //To relate the z-index make sure backdrop and modal are siblings
       $(this).before($('.modal-backdrop'));
       //Now set z-index of modal greater than backdrop
       $(this).css("z-index", parseInt($('.modal-backdrop').css('z-index')) + 1);
    }); 
    
    0 讨论(0)
  • 2020-11-22 17:39

    In my case solve it, add this in my stylesheet:

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

    with google debugger, can examine element BACKDROP And modify attributes. Goog luck.

    0 讨论(0)
提交回复
热议问题