Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap modal won't display if the position of its parent container set to fixed

I have a bootstrap modal which I use it as a instruction guide.

I want to fix it at the top-right corner of the viewport so I use the fixed position. But the modal goes grey with this setting.

If I use the absolute position setting, the modal display fine but it won't be fixed in mobile screens as it will shift with the zoom event.

Here is the fiddle: https://jsfiddle.net/a8Lcj7rk/

like image 577
Frostless Avatar asked Oct 30 '25 11:10

Frostless


2 Answers

Positioned elements works as layers, .modal-backdrop taking z-index-1040 and your .container is on z-index:0 if you want to show it above .modal-backdrop you need to set z-index of .container greater than 1040, in your case 1041 or more.

.container {
  z-index:1041;
}
like image 172
Abhishek Pandey Avatar answered Nov 02 '25 00:11

Abhishek Pandey


Most Simple solution. Just put your modal out side of your container div as I have done below.

Modal markup placement

Always try to place a modal's HTML code in a top-level position in your document to avoid other components affecting the modal's appearance and/or functionality.

Reference for the above is here

.container {
  position: fixed;
  right: 0;
  top: 0;
}
<!DOCTYPE html>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/css/bootstrap-dialog.min.css">

<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">


<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap3-dialog/1.34.7/js/bootstrap-dialog.min.js"></script>

<div class="container">
  <!-- Trigger the modal with a button -->
  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">instruction</button>


</div>
<!-- Modal -->
<div class="modal fade" id="myModal" 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>
like image 42
Shalin Patel Avatar answered Nov 02 '25 02:11

Shalin Patel