Why is my Bootstrap Modal Appearing Behind the Background Overlay?
Bootstrap Modal Hidden Under Background
Issue:
Despite following the official Bootstrap documentation, a modal is appearing beneath the background overlay, preventing interaction.
Reproducing the Issue:
The code for reproducing the problem is similar to the example below:
<body> <p>Lorem ipsum dolor sit amet.</p> <div class="my-module"> <div class="modal fade"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-body">Modal</div> </div> </div> </div> </div> </body>
Root Cause:
The modal container (with the "fade" class) can become hidden when it has a non-default position, such as fixed or relative. This issue occurs when the modal container or its parent elements are positioned differently.
Resolution:
To fix the issue, ensure that the modal container and its parent elements have the default position. There are two approaches to achieve this:
-
Move Modal Outside Positioned Elements:
- Relocate the modal div outside any elements with special positioning (e.g., before the closing