I'm looking for a way to keep a modal dialog within screen bounds, i.e. that its height is always less than the screen height and the width is adjusted accordingly. I tried:
.modal-dialog { max-height: 100%; }
but this doesn't seem to have any effect.
http://jsfiddle.net/ma4zn5gv/
An illustration:
I prefer a pure CSS solution (no js) if it exists. For clarity, I'm looking for max-height, not height (i.e. is the modal is no taller than screen, leave it as is).
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.
Answer: Set width for . modal-dialog element Similarly, you can override the width property of . modal-sm , . modal-lg and . modal-xl class to resize the small, large and extra-large modal dialog box respectively.
The docs reactstrap really bad to explained. Don't forget everyone, you can also do size="xl" . To achieve greater sizes than this, you have to use a stylesheet imported and on the Modal component itself, specifically a property called contentClassName . By writing to a separate file like styles.
Use viewport units with calc
. Like this:
.img-responsive { max-height: calc(100vh - 225px); }
...where the 225px corresponds to the combined height of the top and bottom sections of the viewport which surround the dialog.
Also, in order to take care of the width of the modal we need to set a few more properties:
.modal { text-align:center; } .modal-dialog { display: inline-block; width: auto; }
We can replace calc
with a padding + negative margin technique like so:
.img-responsive { max-height: 100vh; margin: -113px 0; padding: 113px 0; }
PS: browser support for viewport units is very good
Target the modal-body
and not the modal-dialog
.
Add the following to your CSS:
max-height: 80vh; overflow-y: auto;
It should look like this:
.modal-body { max-height: 80vh; overflow-y: auto; }
Adjust the VH height to preference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With