Twitter bootstrap scrollable modal
Solution 1:
How about the below solution? It worked for me. Try this:
.modal .modal-body {
max-height: 420px;
overflow-y: auto;
}
Details:
- remove
overflow-y: auto;
oroverflow: auto;
from .modal class (important) - remove
max-height: 400px;
from.modal
class (important) - Add
max-height: 400px;
to .modal .modal-body (or what ever, can be420px
or less, but would not go more than450px
) - Add
overflow-y: auto;
to.modal .modal-body
Done, only body will scroll.
Solution 2:
I´ve done a tiny solution using only jQuery.
First, you need to put an additional class to your <div class="modal-body">
I called "ativa-scroll", so it becomes something like this:
<div class="modal-body ativa-scroll">
So now just put this piece of code on your page, near your JS loading:
<script type="text/javascript">
$(document).ready(ajustamodal);
$(window).resize(ajustamodal);
function ajustamodal() {
var altura = $(window).height() - 155; //value corresponding to the modal heading + footer
$(".ativa-scroll").css({"height":altura,"overflow-y":"auto"});
}
</script>
I works perfectly for me, also in a responsive way! :)
Solution 3:
/* Important part */
.modal-dialog{
overflow-y: initial !important
}
.modal-body{
max-height: calc(100vh - 200px);
overflow-y: auto;
}
This works for Bootstrap 3 without JS code and is responsive.
Source
Solution 4:
Try and override bootstrap's:
.modal {
position: fixed;
With:
.modal {
position: absolute;
It worked for me.
Solution 5:
I also added
.modal { position: absolute; }
to the stylesheet to allow the dialog to scroll, but if the user has moved down to the bottom of a long page the modal can end up hidden off the top of the visible area.
I understand this is no longer an issue in bootstrap 3, but looking for a relatively quick fix until we upgrade I ended up with the above plus calling the following before opening the modal
$('.modal').css('top', $(document).scrollTop() + 50);
Seems to be happy in FireFox, Chrome, IE10 8 & 7 (the browsers I had to hand)