I have the following element:
-
In latest bootstrap version there is a class to make modal body scrollable.
.modal-dialog-scrollable to .modal-dialog.
Bootstrap modal link for modal body scrollable content
<!-- Scrollable modal -->
<div class="modal-dialog modal-dialog-scrollable">
...
</div>
讨论(0)
-
Or simpler you can put between your tags first, then to the css class.
<div style="height: 35px;overflow-y: auto;"> Some text o othre div scroll </div>
讨论(0)
-
You have to set the height
of the .modal-body
in and give it overflow-y: auto
. Also reset .modal-dialog
overflow value to initial
.
See the working sample:
http://www.bootply.com/T0yF2ZNTUd
.modal{
display: block !important; /* I added this to see the modal, you don't need this */
}
/* Important part */
.modal-dialog{
overflow-y: initial !important
}
.modal-body{
height: 80vh;
overflow-y: auto;
}
讨论(0)
-
In your modal body you have to set a height, it can be % vh or calc:
modal-body {
height: 80vh;
overflow-x: auto;
}
or
modal-body {
height: calc(100vh - 5em);
overflow-x: auto;
}
In my case look like:
讨论(0)
-
Adding on to Carlos Calla's great answer.
The height of .modal-body must be set, BUT you can use media queries to make sure it's appropriate for the screen size.
.modal-body{
height: 250px;
overflow-y: auto;
}
@media (min-height: 500px) {
.modal-body { height: 400px; }
}
@media (min-height: 800px) {
.modal-body { height: 600px; }
}
讨论(0)
-
If you're only supporting IE 9 or higher, you can use this CSS that will smoothly scale to the size of the window. You may need to tweak the "200px" though, depending on the height of your header or footer.
.modal-body{
max-height: calc(100vh - 200px);
overflow-y: auto;
}
讨论(0)