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
This should work for everyone, any screen resolutions:
.modal-body {
max-height: calc(100vh - 143px);
overflow-y: auto; }
First, count your modal header and footer height, in my case I have H4
heading so I have them on 141px
, already counted default modal margin in 20px(top+bottom)
.
So that subtract 141px
is the max-height
for my modal height, for the better result there are both border top and bottom by 1px
, for this, 143px
will work perfectly.
In some case of styling you may like to use overflow-y: auto;
instead of overflow-y: scroll;
, try it.
Try it, and you get the best result in both computer or mobile devices.
If you have a heading larger than H4
, recount it see how much px
you would like to subtract.
If you don't know what I am telling, just change the number of 143px
, see what is the best result for your case.
Last, I'd suggest have it an inline CSS.