Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-bootstrap Modal size

What is the best way to set/override a custom width for a modal?

It seems ng-bootstrap currently supports

size: 'sm' | 'lg'

but Bootstrap 4 supports sm, md and lg.

Ideally I would like the modal to be responsive and adjust similar to container sizes. And on mobile have it go full screen.

EDIT: Bootstrap 4 _variables.scss seems to have a $modal-md setting but appears to be unused.

$modal-lg:                    800px !default; $modal-md:                    500px !default; $modal-sm:                    300px !default; 
like image 801
Todd Smith Avatar asked Oct 27 '17 14:10

Todd Smith


People also ask

How do I change the size of a bootstrap modal?

Change the size of the modal by adding the . modal-sm class for small modals, . modal-lg class for large modals, or . modal-xl for extra large modals.

How do you change modal height?

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.


1 Answers

The cleanest solution that I could find is to use the windowClass property.

I.e.:

this.modalService.open(MyModalComponent,  { windowClass : "myCustomModalClass"}); 

Then add the following to your global CSS styles. This is important as the style won't be picked up from your components CSS.

.myCustomModalClass .modal-dialog {   max-width: 565px; } 
like image 147
TomDK Avatar answered Nov 05 '22 08:11

TomDK