I am trying to make a modal with a body that will scroll when the content becomes too large. However, I want the modal to be responsive to the screen size. When I set the max-he
The scss
solution for Bootstrap 4.0
.modal {
max-height: 100vh;
.modal-dialog {
.modal-content {
.modal-body {
max-height: calc(80vh - 140px);
overflow-y: auto;
}
}
}
}
Make sure the .modal
max-height
is 100vh
. Then for .modal-body
use calc()
function to calculate desired height. In above case we want to occupy 80vh
of the viewport, reduced by the size of header + footer in pixels. This is around 140px together but you can measure it easily and apply your own custom values. For smaller/taller modal modify 80vh
accordingly.