I have a problem, with a modal. I have a button on a page, that toggles the modal. When the modal shows up, the page jumps to top.
I have done everything I could to
I had the same problem and I think I figure it out. You just need to place the modal HTML as a direct child of the body tag! You can place the HTML code for the button triggering the modal wherever you need though. I believe this avoids CSS inheritance and position issues that trigger this problem.
Example:
<body>
<!-- All your other HTML code -->
<div>
<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
Launch demo modal
</button>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
</body>
Try this it works perfectly
/* fix body.modal-open overflow:hidden */
body.modal-open {
height: auto;
}
I tried to set .modal top at the center of the screen.
.modal {
position: absolute;
top: 50%;
}
Just my 2cents of thoughts.
Try using this to open modal and see what happens:
<a href="#generalModal" class="btn btn-primary btn-lg" data-toggle="modal">
Launch demo modal
</a>
body.modal-open {
position: inherit;
}
This worked like a charm for me.
This one did it for me
body.modal-open {
overflow: inherit;
padding-right: 0 !important;
}