Just move the entire modal outside of the rest of your code, to the very bottom. It doesn't need to be nested in any other element, other than the body.

<body>
    <!-- All other HTML -->
    <div>
        ...
    </div>

    <!-- Modal -->
    <div class="modal fade" id="myModal">
        ...
    </div>
</body>

Demo

They hint at this solution in the documentation.

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.

Answer from Schmalzy on Stack Overflow
🌐
MDBootstrap
mdbootstrap.com › standard › modal backdrop
Bootstrap Modal Backdrop - free examples & tutorial
Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. Default modal backdrop is a delicate shadow overlaying the rest of the page design.
🌐
Bootstrap
getbootstrap.com › docs › 4.4 › components › modal
Modal · Bootstrap
It also adds .modal-open to the <body> to override default scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal.
🌐
Bootstrap
getbootstrap.com › docs › 5.0 › components › modal
Modal · Bootstrap v5.0
The modal plugin toggles your hidden ... scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal....
🌐
Bootstrap
getbootstrap.com › docs › 5.3 › components › modal
Modal · Bootstrap v5.3
The modal plugin toggles your hidden ... scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal....
🌐
GitHub
github.com › mdbootstrap › bootstrap-modal-backdrop
GitHub - mdbootstrap/bootstrap-modal-backdrop: Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. · GitHub
Backdrop options for a responsive popup with Bootstrap 5. Prevent close on click outside with static backdrop, remove backdrop, enable interactivity & more. - mdbootstrap/bootstrap-modal-backdrop
Author   mdbootstrap
🌐
Rick Strahl's Web Log
weblog.west-wind.com › posts › 2016 › sep › 14 › bootstrap-modal-dialog-showing-under-modal-background
Bootstrap Modal Dialog showing under Modal Background - Rick Strahl's Web Log
September 14, 2016 - The problem is that the .modal-backdrop overlay sits in the root of the DOM tree while the other content is buried in a separate DOM node tree. If anything inside of that tree is relatively positioned, the z-index can no longer be compared effectively. You can try using the following (Bootstrap 4 - in 3 use .modal-dialog instead of .modal-content:
🌐
W3Schools
w3schools.com › bootstrap › tryit.asp
Modal Options
The W3Schools online code editor allows you to edit code and view the result in your browser
🌐
Bootstrap
getbootstrap.com › docs › 4.6 › components › modal
Modal · Bootstrap v4.6
It also adds .modal-open to the <body> to override default scrolling behavior and generates a .modal-backdrop to provide a click area for dismissing shown modals when clicking outside the modal.
Find elsewhere
🌐
CodePen
codepen.io › artzeeone › pen › yJVJBr
Custom Bootstrap modal backdrops
.modal-backdrop { background-color: transparent; } .modal-backdrop-transparent { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background-color: transparent; opacity: 0; width: 100%; height: 100%; z-index: -1000; } .modal-backdrop-orange { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background-color: orange; opacity: 0.6; width: 100%; height: 100%; z-index: 1040; } .modal-backdrop-blue { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background-color: blue; opacity: 0.6; width: 100%; height: 100%; z-index: 1040; } .modal-transition { transition: all 0.4s ease; }
🌐
CodePen
codepen.io › cristinaconacel › pen › ZmxgYm
Bootstrap 4 Basic Modal with Static Backdrop
<div class="container"> <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#glassAnimals" data-backdrop="static"> Glass Animals Info </button> </div> <div class="modal fade" id="glassAnimals" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog modal-dialog-centered" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Glass Animals</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">&times;</span> </button> </div> <div class="modal-body"> Glass Animals are an English indie rock band from Oxford consisting of members Dave Bayley (lead vocals, guitar), Drew MacFarlane (guitar, keys, backing vocals), Edmund Irwin-Singer (bass, keys, backing vocals), and Joe Seaward (drums).
🌐
Codeply
codeply.com › go › oNKsVikW6n
Bootstrap 4 modal backdrop color on Codeply
HTML, CSS, JavaScript editor playground for designers & developers to compare, prototype and test frontend frameworks
🌐
GeeksforGeeks
geeksforgeeks.org › bootstrap › bootstrap-5-modal-static-backdrop
Bootstrap 5 Modal Static backdrop - GeeksforGeeks
November 30, 2022 - Bootstrap 5 Modal Static backdrop facilitates the modal that will not be going to be closed while clicking outside of the modal, by setting the backdrop to static.