Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Modal opens but stays in gray background and cannot close or interact with modal

I am using Bootstrap's Modal class to have a modal appear after clicking a button. The code works - the button is clicked and the modal appears, however, the whole screen is grayed-out and the modal cannot be clicked. I cannot close the modal since it is "in" the gray background. You can see in the image below: Modal in gray background

Here is the code:

    <!-- Modal -->
<div id="myModal" class="modal fade" style="z-index: 9999;" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <p>Some text in the modal.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
<section id="profileMain">
    <form class="formoid-solid-dark"
        style="background-color: #FFFFFF; font-size: 14px; font-family: 'Trebuchet MS','Roboto', Arial, Helvetica, sans-serif; color: #34495E; max-width: 800px; min-width: 150px"
        method="post" action="">
        <div class="title">
            <h2>Intake Request</h2>
        </div>
        <div id="mainFormTabs" class="container">
            <ul class="nav nav-pills">
                <li><a data-toggle="tab" href="#tabCM">Comments</a></li>
            </ul>
            <div class="container" style="border:1px solid #34495E; border-radius: 0px 4px 4px 4px;">
                <div class="tab-content clearfix" style="padding: 10px;">
                    <div id="tabCM" class="tab-pane fade">
                        <!-- Trigger the modal with a button -->
                        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</section>

I have tried adjusting the z-index for the modal, I have moved the modal div outside the body, at the top, and at the bottom of the html form, but none of these worked.

I appreciate any ideas on how to fix this.

like image 576
Dan Avatar asked Dec 22 '16 22:12

Dan


People also ask

How do I close a Bootstrap modal?

Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.

How do I stop Bootstrap modal from hiding when clicking outside?

When the Button is clicked, the HTML DIV is referenced using jQuery and its modal function is called along with properties data-backdrop: "static" and data-keyboard: false which disables the closing of the Bootstrap Modal Popup when clicked outside.

Do not close modal popup Bootstrap outside click?

On Options chapter, in the page you linked, you can see the backdrop option. Passing this option with value 'static' will prevent closing the modal. As @PedroVagner pointed on comments, you also can pass {keyboard: false} to prevent closing the modal by pressing Esc .


1 Answers

I went back and moved the modal div outside the body tag and it is now working.

</body>
<!-- Modal -->
<div id="myModal" class="modal fade" style="z-index: 9999;" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <p>Some text in the modal.</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>
</html>
like image 142
Dan Avatar answered Oct 04 '22 01:10

Dan