17

Using Bootstrap to add a modal popup. Upon clicking the trigger button, the modal is dark and unclickable. Any idea what's causing this or where to look?

enter image description here

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


<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

application.js

//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require miracle/jquery.noconflict
//= require miracle/modernizr.2.8.3.min
//= require miracle/jquery-migrate-1.2.1.min
//= require miracle/jquery-ui.1.11.2.min
//= require bootstrap
//= require turbolinks
//= require magnific-popup/jquery.magnific-popup.min
//= require miracle/jquery.stellar.min
//= require miracle/waypoints.min
//= require owl-carousel/owl.carousel.min
//= require jquery.sky.carousel/jquery.sky.carousel-1.0.2
//= require miracle/jquery.plugins
//= require miracle/main
//= require_tree .
Drenmi
  • 8,492
  • 4
  • 42
  • 51
Onichan
  • 4,476
  • 6
  • 31
  • 60
  • 3
    You need to post the rest of your code/output (HTML/CSS/JS), as the modal itself works fine. This is most likely due to where the modal has been placed. – vanburen Oct 24 '15 at 04:27
  • I've tried placing the code in various places and the result is the same. I suspect this could be caused by a jquery conflict? – Onichan Oct 24 '15 at 04:30
  • Well, you also have Magnific included, so I wouldn't be surprised if there's a CSS conflict happening. Basically, the z - index of the modal looks to be wrong. – Tieson T. Oct 24 '15 at 04:33
  • @vanburen you pointed me in the right direction. Looks like I just had to move the modal to the very bottom of the html right before `

    ` and leave the trigger button where it is. This also helped: http://stackoverflow.com/questions/20983110/bootstrap-modal-sitting-behind-backdrop/20983718#20983718

    – Onichan Oct 24 '15 at 04:35
  • Sounds good and glad I could help. – vanburen Oct 24 '15 at 04:36
  • Can you give me a jsfiddle url or live demo? – Sarower Jahan Oct 24 '15 at 10:24

6 Answers6

44

i solved the same problem when i add data-backdrop="false" in my modal like this:

<div class="modal fade" id="userGoing" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" data-backdrop="false">
sara elsayed
  • 449
  • 4
  • 4
7

Sometimes, changing the z-index can mess up things with Bootstrap so as they say in Bootstrap documentation, try to place your <!-- Modal --> block on top of your page. If it's a modal that is accessible from many places in your app you can place it in a partial and call it on top of your app/views/layouts/application.html.erb like so (sorry, it's a slim template, tell me if you need erb translation):

doctype html
html
  head
    == render 'layouts/meta'

    = stylesheet_link_tag …
    = javascript_include_tag …
    = csrf_meta_tags

  body

    == render 'path/to/your/modal'

    .container
      == yield

    == render 'layouts/footer'

Otherwise, you could try to do a special <%== yield :modal %> in your application.html.erb and call it from somewhere else with `<%- content_for :modal %>. Not sure about the erb syntax here. It's explained here : Using The Content For Method

Sifnos
  • 1,161
  • 2
  • 13
  • 22
  • I currently have the model in the application.html.erb, but I'm not sure how to pass a variable from the view (that's calling the model) to the model itself. Currently trying to use javascript, but is there a better approach? – Onichan Oct 24 '15 at 10:22
  • This means you must use the second technique. The first one would only work if you were calling an instance variable such as `@something` created by ApplicationController. Something you need to access from anywhere in your app. For the second technique, in your `application.html.erb`, instead of placing your modal directly (or by rendering a partial), place a `<%= yield :modal %>`. Then, in your view, inside a `<%- content for :modal %>` block, you can place your modal or render a partial. This will place your modal on top of the rest. – Sifnos Oct 24 '15 at 17:20
  • placing block on top of your page, works for me. – Zafar Jun 13 '21 at 08:46
4

Add the below code in the same page.

#myModal{
 z-index: 9999
}
Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Chakreshwar Sharma
  • 2,571
  • 1
  • 11
  • 35
1

.modal-dialog has pointer-events set to none.

I overwrote that property and set pointer-events: unset;

so:

.modal-dialog {
  pointer-events: unset !important;
}

This did the trick for me

0

I had the same problem when I call a modal from another modal (but not when I call only the first one).

So, this might not help you but it can save someone else a lot of time: I had a different definition of fade effects and there was the line with display: inline-block. I removed it and the problem's gone.

The failing CSS definition:

.fade {
    ...
    display: inline-block;
    ...
}
Emir
  • 380
  • 3
  • 11
0

After long time, i got this simple error just by

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

Thanks.

Y. Joy Ch. Singha
  • 3,056
  • 24
  • 26