Bootstrap 3 modal vertical position center

后端 未结 30 1174
天涯浪人
天涯浪人 2020-11-28 00:15

This is a two part question:

  1. How can you position the modal vertically in the center when you don\'t know the exact height of the modal?

  2. Is

30条回答
  •  [愿得一人]
    2020-11-28 01:01

    I know it's a bit late, but I am adding a new answer so that it doesn't get lost in the crowd. It's a cross-desktop-mobile-browser solution that works everywhere properly as it should.

    It just needs the modal-dialog to be wrapped inside a modal-dialog-wrap class and need to have the following code additions:

    .modal-dialog-wrap {
      display: table;
      table-layout: fixed;
      width: 100%;
      height: 100%;
    }
    
    .modal-dialog {
      display: table-cell;
      vertical-align: middle;
      text-align: center;
    }
    
    .modal-content {
      display: inline-block;
      text-align: left;
    }
    

    The dialog starts centered and in cases of large content it simply grows vertically until a scrollbar appears.

    Here is a working fiddle for your pleasure!

    https://jsfiddle.net/v6u82mvu/1/

提交回复
热议问题