JSFiddle - React, Tailwind, and code Playground
by BenjaminRay
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div>
<button id="btn">Open Modal</button>
<div class="red block">
</div>
<div class="blue block">
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</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>
</div>
</div>
CSS
body {
background-color: #ff00ff;
}
.after_modal_appended
{
position:relative;
}
.red
{
background-color:red;
}
.blue
{
background-color:blue;
}
.block
{
width:100%;
height:200px;
}
.modal, .modal-backdrop {
position: absolute !important;
}
JavaScript
$(document).ready(function(){
$("body").on("click","#btn",function(){
$("#myModal").modal("show");
$(".blue").addClass("after_modal_appended");
//appending modal background inside the blue div
$('.modal-backdrop').appendTo('.blue');
//remove the padding right and modal-open class from the body tag which bootstrap adds when a modal is shown
$('body').removeClass("modal-open")
$('body').css("padding-right","");
});
});