18

How can I set the width to my ngx bootstrap modal, I've tried but like It is fixed?

Here's the html

    <div bsModal #childModal="bs-modal" class="modal fade" tabindex="-1" 
     role="dialog" [config]="{backdrop: 'static'}" aria-hidden="true">
    <div class="modal-dialog modal-sm">
    <div class="modal-content">
        <div class="modal-body text-center">
            <button type="button" class="close" data-dismiss="modal" aria-
    label="Close" (click)="hide()"><span aria-hidden="true">&times;</span>
     </button>
            <h4 class="modal-title" id="myModalLabel">Are you sure?</h4>
            <div class="modal-footer">
                <div class="col-xs-6 no-padding-left">
                    <button type="button" id="dialog_no" class="btn btn-
        default btn-block" data-dismiss="modal" (click)="hide()">No</button>
                </div>
                <div class="col-xs-6 no-padding-right">
                    <button type="button" id="dialog_yes" class="btn btn-
     primary btn-block ladda-button" data-style="expand-right" 
     (click)="confirm()">Yes</button>
                </div>
            </div>
        </div> 
    </div>
     </div>
  </div>

How can I set the width of the modal for buttons to be placed just on the edge of the modal, with lets say 5 px of border margin?

modal bootstrap

I haven't put any styling yet in my css file, even tho I've tried to modify the width but didn't I guess know how...

code_newbie23
  • 191
  • 1
  • 1
  • 5

11 Answers11

21

On your method call for the modal, you can setup a configuration object with the ModalOptions class that also comes with ngx-bootstrap. Within that, the 'class' property allows you to pass classes which will be appended.

const config: ModalOptions = { class: 'modal-sm' };
this.bsModalRef = this.modalService.show(YourComponent, config);

hope this helps

jgritten
  • 915
  • 1
  • 11
  • 20
9

When creating a modal, pass your css class to options like this:

this.modalService.show(template, { class: 'modal-lg' });
Akash Kumar Verma
  • 3,185
  • 2
  • 16
  • 32
Savan Gadhiya
  • 1,082
  • 2
  • 11
  • 16
7

similar to @jgrittens response.

this.modalRef = this.modalService.show(template);
this.modalRef.setClass('modal-sm');

it sets the max-width to 300px

LuckyLikey
  • 3,504
  • 1
  • 31
  • 54
5

You can simply use the below style to overwrite the original dimension of modal

::ng-deep .modal-dialog{
    max-width: 1200px !important;
    width: 1200px;
  }
NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
Dhruv Patadia
  • 152
  • 2
  • 10
3

I would suggest adding "encapsulation: ViewEncapsulation.None" to your component decorator and then override the class with something like:

 .modal-dialog{
    max-width: 600px !important;
    width: 600px !important;
  }
Jay Ordway
  • 1,708
  • 2
  • 11
  • 33
2

Use Set Class

let modal = this.bsModalService.show(ConfirmModalComponent, { 
         initialState: { message: 'คุณแน่ใจหรือไม่ว่าจะลบข้อมูล Voucher นี้?' },});

modal.setClass('modal-custom-style');

And Custom CSS

::ng-deep .modal-custom-style { max-width: 1200px!important; width: 1200px; }

Bijin Abraham
  • 1,709
  • 2
  • 11
  • 25
  • You can edit all css in this modal , Example : // --- Modal CSS -- // ::ng-deep .modal-custom-style { max-width: 380px !important; width: 380px; max-height: 290px !important; height: 290px; .modal-content { border: none !important; } } – Jaroon Umpornpoolsuk May 20 '21 at 03:09
0

You can use only CSS styles to change the width of the container. Change max-width property for .modal-dialog class, in some cases for .modal-sm class.

0

You can use doucment.getelementsbyClassName after you create the modal. Then you can change the element minWidth as you wish.

hiFI
  • 1,887
  • 3
  • 28
  • 57
jim
  • 1
0

just add this line in your ts file: config: ModalOptions = { class: 'modal-lg' }; then pass config also in the show method of BsModal sERVICE

EXAMPLE:

config: ModalOptions = { class: 'modal-lg' };
openModal(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, this.config);

}

0

This works for me. In styles.scss...

.modal-lg {
    max-width: 559px !important;
}
aarffy
  • 231
  • 2
  • 13
0

What worked for me was ::ng-deep with .modal-content, but only after I placed the !important property

::ng-deep .modal-content {
    max-width: 1080px!important;
}