Bootstrap Modal visible on document load

2019-03-01 21:46发布

问题:

I have a Bootstrap Model working fine, except that it is visible when the document loads and I can't work out how to make the initial state invisible?

<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>


<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>

回答1:

Following documentation, add hide class to the modal.

<div class="modal hide fade">
    ...
</div>


回答2:

Turns out simply adding style="display: none" to the modal outer div did the trick.