Ngx-bootstrap: Any option to set the modals to show in center

Created on 1 Aug 2017  路  14Comments  路  Source: valor-software/ngx-bootstrap

When I use the models i am able to show them on top. Is there any solution to show on different places of the page. or do you have any css to to place at center. I wrote a css when i apply it on console element it works but when i apply from code end it does not work as this is a template

comp(modal)

Most helpful comment

Boostrap 4 itself already has a class to center the modal, it's called 'modal-dialog-centered'. You just need to add it to the 'modal-dialog' element.

Example:

const config = {
  ignoreBackdropClick = true;
  class: 'modal-dialog-centered'
}
this.bsModalService.show(ModalComponent, config);

All 14 comments

Apply a custom class to modal and work with it. You can show modal in center using css rules like margin, position, transform:translateY(), or using flexbox model.

I've tried to use the provided CSS in my custom component but it's not working

I'm very surprised that no example talks about how to center modals in the documentation.

all the modals are shows in top of the screen ...

I've asked a question here: https://stackoverflow.com/questions/46898035/how-to-center-an-ngx-bootstrap-modal

but no answer yet

what to add to the example: Modal with component, that it can show in the center ?

can the documentation be updated to include positioning ?

Boostrap 4 itself already has a class to center the modal, it's called 'modal-dialog-centered'. You just need to add it to the 'modal-dialog' element.

Example:

const config = {
  ignoreBackdropClick = true;
  class: 'modal-dialog-centered'
}
this.bsModalService.show(ModalComponent, config);

@JanLoebel Thanks . It worked for me :)

@JanLoebel added class modal-dialog-centered, but no effect. Which version of bootstrap does support this class?

@harsimerkaur I'm using version bootstrap 4.0.0.

@JanLoebel I am using version 3.3.7 and I am able to add class but neither modal-dialog-centered has any effect on modal nor any custom CSS does apply. I am using ngx-bootstrap modal. Didn't find any solution on stackoverflow either.

@harsimerkaur I'm using "ngx-bootstrap" in version 2.0.4 and bootstrap in version 4.0.0. When you want to apply custom css, be aware that it could be that you will have to wrap it in a ::ng-deep.

::ng-deep {
  .modal-dialog-centered {
    border: 1px solid red;
  }
}

Have you checked that the class modal-dialog-centered is applied in the DOM?

Yes class is added to modal, checked in DOM. I used

:host ::ng-deep

.modal-dialog-centered
{
justify-content: center;
align-items: center;
}

and

:host >>>

.modal-dialog-centered
{
justify-content: center;
align-items: center;
}

None worked.

justify-content is flex prroperty
only bootstrap 4 has flex

@fchiumeo It works when I add it in browser console directly. moreover no other CSS works,

@JanLoebel @fchiumeo Added CSS in project\src\styles.css and it worked. Thanks for help!

Was this page helpful?
0 / 5 - 0 ratings