How to vertically align Bootstrap v4 modal dialogs

后端 未结 10 1404
轻奢々
轻奢々 2020-12-08 02:45

Vertically center modal dialogues in Bootstrap 4.

Note: The requirements below have been added to make it clear I am looking for a prop

10条回答
  •  旧巷少年郎
    2020-12-08 03:23

    There is a much easier way of achieving this without having to write a bunch of CSS overrides or other custom CSS, basically using just the stock bootstrap classes and adding one extra HTML element to control the height.

    CSS (Not Needed see below)

    .modal > .row{
        flex: 1;
    }
    

    HTML (Updated see below)

    
    

    Then to use:


    JS

    $("#dialogBox").modal('show');
    

    OR HTML

    
    

    There is probably a way to achieve the desired result using only the bootstrap .row, .col and flex-XXX classes but I was unable to get that to work.

    One last note, you might have to add: to get everything to work depending on the rest of your CSS.

    UPDATE


    There is a way to achieve this using only bootstrap classes, h-100 and w-100:

    
    

提交回复
热议问题