center Angular UI 模态框在屏幕中间

Center Angular UI Modal in the middle of the screen

我遵循了 here but it's not working. I need to center the modal right in the middle of the screen, both horizontally and vertically. I attempted in this plunk 中的解决方案,但它不起作用,有什么想法吗?

Javascript

var app = angular.module('app', ['ui.bootstrap']);
app.controller('ctl', function ($scope,$uibModal) {

    $scope.modalInstance = $uibModal.open({
        templateUrl: 'myModalContent.html',
        windowClass: 'app-modal',
      }); 
});

HTML

  <style>
      .app-modal .modal-content {
          width: 360px;
          height: 200px;
        }
  </style>

  <script type="text/ng-template" id="myModalContent.html">

    <div class="modal-header">
        <h4 class="modal-title">The Title</h4>
    </div>

    <p>Some text</p

 </script>

在您的 css 中,试试这个:

.modal-dialog {
    position: absolute;
    top: 50%;
    /*half of the modal height*/
    margin-top: -100px;
    left: 50%;
    /*half of the modal width*/
    margin-left: -180px;
}

要使模态框在 bootstrap 中居中,您可以将 transform: translate(-50%, -50%);postion: absolute; 属性.

结合使用
<style>
.modal-dialog {
  margin: 0;
  top: 50%;
  position: absolute;
  left: 50%;
  transform: translate(-50%,-50%);
}
</style>

不要忘记将边距归零 margin: 0;