angularjs - 在屏幕中间居中 Angular UI 模态

标签 angularjs angular-ui-bootstrap angular-ui

我遵循了取自 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>

最佳答案

要在 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;

关于angularjs - 在屏幕中间居中 Angular UI 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40498909/

相关文章:

javascript - 为什么父组件和子组件之间的双向绑定(bind)不好?

css - 让 col-md-4 float ,col-md-8 滚动

angularjs - 为什么在 ngClick 之后,missing-on-timeout 不适用于 ui-bootstrap 的警报指令?

javascript - Angular UI-Router - 直接在模板 url 上使用 "resolve"

javascript - 向具有固定标题的表格添加滚动条

angularjs - Angular 1.5.0-beta.0 : angular. module(...).component 不是函数

javascript - 使用 javascript 添加更多功能时不显示文本编辑器

javascript - 将 Bootstrap CSS 类应用于给定类型的所有 HTML 元素

angularjs - 包装 angular-ui tabset 指令并遇到 "Multiple directives asking for transclusion/isolated scope"错误

javascript - 如何在文本字段 AngularJS 中验证 IP