Bootstrap model covered by modal backdrop

Ad

I have simple html page to show bootstrap modal, however when I launch the model - it gets covered by modal backdrop, I checked the z- index of myModal - 1040 and that of modal backdrop is 1030 checked all posts in stackoverflow but none of them solve my issue please help

<html>
<head>
    <link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="" rel="stylesheet">
    <link target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="Content/bootstrap.min.css" rel="stylesheet">
    <script src="Scripts/jquery-1.10.2.min.js"></script>
    <script src="Scripts/bootstrap.min.js"></script>
</head>
<body>




    <a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

    <div id="myModal" class="modal hide fade in" aria-hidden="true">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">X</button>
            <h3 id="myModalLabel">Log in</h3>
        </div>
        <div class="modal-body">
            <form class="modal-form" id="loginform">
                <input type="text" name="username" placeholder="login" id="username">
                <input type="text" name="password" placeholder="password" id="userpassword">
            </form>
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
            <button class="btn btn-success">Login</button>
        </div>
    </div>

</body>
</html>​
Ad

Answer

Ad

You forgot a few things, which are:

  • the <div class="modal-dialog">
  • the <div class="modal-content">

You also added some unecessary things which are:

  • the hide class on the <div id="myModal" class="modal fade in" aria-hidden="true">
  • the in class on the <div id="myModal" class="modal fade in" aria-hidden="true">

Your working code will look like this:

<a target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<div id="myModal" class="modal fade in" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">X</button>
        <h3 id="myModalLabel">Log in</h3>
      </div>
      <div class="modal-body">
        <form class="modal-form" id="loginform">
          <input type="text" name="username" placeholder="login" id="username">
          <input type="text" name="password" placeholder="password" id="userpassword">
        </form>
      </div>
      <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
        <button class="btn btn-success">Login</button>
      </div>
    </div>
  </div>
</div>

Here's a JsFiddle to show it in a working environment.

To read everything about the modal, please check this

Hope this helps!

Ad
source: stackoverflow.com
Ad