Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bootstrap and bootbox: set dialog box center of the screen

I am using bootbox.js from http://bootboxjs.com/examples.html and it is quite impressive. But I have an issue while setting up the location of the dialog box.

I want to place dialog box center of the screen. I am using this code but dialog box stays on top of the screen.

 bootbox.alert('Danger!!').find('.modal-content').css({
     'background-color': '#f99',
     'font-weight': 'bold',
     color: '#F00',
     'top': '50%',
     'margin-top': function() {
         return -(box.height() / 2);
     },
     'font-size': '2em',
     'font-weight': 'bold'
 });

Please advise how can set the dialog box center of the screen.

like image 243
Roxx Avatar asked Jun 27 '16 03:06

Roxx


People also ask

What is a Bootbox and how it is generated?

js is a small JavaScript library which allows you to create programmatic dialog boxes using Bootstrap modals, without having to worry about creating, managing, or removing any of the required DOM elements or JavaScript event handlers.

How do I close Bootbox dialog?

Pressing the ESC key or clicking close () dismisses the dialog and invokes the callback as if the user had clicked the Cancel button. Confirm dialogs require a callback function.


1 Answers

If you want a vertical centered bootbox modal via css3

.modal-open .modal {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

You can have more flexibility here: https://www.kirupa.com/html5/centering_vertically_horizontally.htm https://css-tricks.com/snippets/css/a-guide-to-flexbox/

like image 143
Emanuele Pogliani Avatar answered Sep 17 '22 14:09

Emanuele Pogliani