Bootstrap modal appearing under background

前端 未结 30 976
离开以前
离开以前 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:21

    set the z-index .modal to a highest value

    For example, .sidebarwrapper has z-index of 1100, so set the z-index of .modal to 1101

    .modal {
        z-index: 1101;
    }
    
    0 讨论(0)
  • 2020-11-22 17:24

    An other way to approach this is to remove the z-index from the .modal-backdrop in bootstrap.css. This will cause the backdrop to be on the same level as the rest of your body (it will still fade) and your modal to be on top.

    .modal-backdrop looks like this

    .modal-backdrop {
      position: fixed;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: #000000;
    }
    
    0 讨论(0)
  • 2020-11-22 17:24

    Hi I had the same issue then I realize that when you using bootsrap 3.1 Unlike in older versions of bootsrap (2.3.2) the html structure of the modal was changed!

    you must wrap your modal header body and footer with modal-dialog and modal-content

    <div class="modal hide fade">
    
      <div class="modal-dialog">
        <div class="modal-content">
    
        **here goes the modal header body and footer**
    
        </div>
      </div>
    
     </div>
    
    0 讨论(0)
  • 2020-11-22 17:24
    $('.modal').insertAfter($('body'));
    
    0 讨论(0)
  • 2020-11-22 17:25

    If the modal container has a fixed or relative position or is within an element with fixed or relative position this behavior will occur.

    Make sure the modal container and all of its parent elements are positioned the default way to fix the problem.

    Here are a couple ways to do this:

    1. Easiest way is to just move the modal div so it is outside any elements with special positioning. One good place might be just before the closing body tag </body>.
    2. Alternatively, you can remove position: CSS properties from the modal and its ancestors until the problem goes away. This might change how the page looks and functions, however.
    0 讨论(0)
  • 2020-11-22 17:25

    I had this issue and the easiest way to fix it was addind z-index greater than 1040 on the modal-dialog div:

    <div class="modal-dialog" style="z-index: 1100;">
    

    I believe bootstrap create a div modal-backdrop fade in which in my case has the z-index 1040, so if You put the modal-dialog on top of this, it should not be grey out anymore.

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