Vertically centering Bootstrap modal window

前端 未结 30 2006
被撕碎了的回忆
被撕碎了的回忆 2020-12-07 07:00

I would like to center my modal on the viewport (middle) I tried to add some css properties

 .modal { position: fixed; top:50%; left:50%; }   
30条回答
  •  不知归路
    2020-12-07 07:32

    For those who are using angular-ui bootstrap can add the below classes based on above info:

    Note: No other changes are needed and it shall resolve all modals.

    // The 3 below classes have been placed to make the modal vertically centered
    .modal-open .modal{
        display:table !important;
        height: 100%;
        width: 100%;
        pointer-events:none; /* This makes sure that we can still click outside of the modal to close it */
    }
    
    .modal-dialog{
        display: table-cell;
        vertical-align: middle;
        pointer-events: none;
    }
    
    .modal-content {
        /* Bootstrap sets the size of the modal in the modal-dialog class, we need to inherit it */
        width:inherit;
        height:inherit;
        /* To center horizontally */
        margin: 0 auto;
        pointer-events: all;
    }
    

提交回复
热议问题