【问题标题】:Center Angular UI Modal in the middle of the screen在屏幕中间居中 Angular UI 模态
【发布时间】:2016-11-09 11:10:35
【问题描述】:

我遵循了从here 获取的解决方案,但它不起作用。我需要将模式在屏幕中间居中,水平和垂直。我尝试了这个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>

【问题讨论】:

    标签: angularjs angular-ui-bootstrap angular-ui


    【解决方案1】:

    要使您的模式在引导程序中居中,您可以将transform: translate(-50%, -50%);postion: absolute; 属性结合使用。

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

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

    【讨论】:

      【解决方案2】:

      在你的 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;
      }
      

      【讨论】:

        猜你喜欢
        • 2017-01-30
        • 2020-06-03
        • 2016-04-07
        • 2019-05-16
        • 2021-10-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-16
        • 1970-01-01
        相关资源
        最近更新 更多