2

I followed the solution taken from 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 but it's not working, any ideas?

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>
Community
  • 1
  • 1
ps0604
  • 1,227
  • 23
  • 133
  • 330

2 Answers2

4

To center your modal in bootstrap you can use transform: translate(-50%, -50%); in combination with the postion: absolute; property.

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

Don't forget to zero out the margins margin: 0;

bob
  • 983
  • 11
  • 21
3

In your css, try this:

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