ooo-Ghost-ooo ooo-Ghost-ooo -4 years ago 121
HTML Question

Modal scrolls fails to work if i have modal inside a modal

I have a modal within a modal and it works properly. but then i notice when the 1st modal exceed from the screen and appears a scroll for the 1st modal it works but when i open the second modal and close it, the 1st modal won't scroll.

Heres a snippet to show you.



<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test1">Open Modal 1 </button>



<div id="test1" class="modal fade" role="dialog" style="z-index: 1400;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">

<div class="modal-body">
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>
sample<br>

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test2">Open Modal 2</button>

</div>
</div>
</div>
</div>

<div id="test2" class="modal fade" role="dialog" style="z-index: 1600;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">

<div class="modal-body">

content

</div>
</div>
</div>
</div>


</body>
</html>





does anyone know why it fails to scroll when i open and close the 2nd modal.?
Thanks in Advance.

Answer Source

set overflow: auto; to your #test1 container. this will be the solutiuon

#test1 {
overflow: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <title></title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>

  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#test1">Open Modal 1 </button>



<div id="test1" class="modal fade" role="dialog" style="z-index: 1400;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>
        sample<br>

      	<button type="button" class="btn btn-info btn-lg" data-toggle="modal"      data-target="#test2">Open Modal 2</button>
      	
      </div>      
    </div>
  </div>
</div>

<div id="test2" class="modal fade" role="dialog" style="z-index: 1600;">
  <div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
      	
        content
      	
      </div>      
    </div>
  </div>
</div>
  

</body>
</html>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download