Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit the height of the modal?

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:

enter image description here

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).

like image 859
georg Avatar asked Mar 01 '15 09:03

georg


People also ask

How can I reduce my modal height?

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.

How do you reduce the width of a modal?

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.

How do you increase modal size in Reactstrap?

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.


2 Answers

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; } 

Updated Fiddle (Resize the viewport height to see the effect)


Alternatively:

We can replace calc with a padding + negative margin technique like so:

.img-responsive {     max-height: 100vh;     margin: -113px 0;     padding: 113px 0; } 

FIDDLE

PS: browser support for viewport units is very good

like image 86
Danield Avatar answered Sep 28 '22 17:09

Danield


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.

like image 22
Juan J Avatar answered Sep 28 '22 17:09

Juan J