具有高z-index的Angular UI模式不在顶部

时间:2016-07-05 15:08:37

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

In this plunk我有一个Angular UI模态,其z-index大于div z-index,但div覆盖了模态。如果你点击div,你会看到模态已经落后了。

由于模态的z-index较大,我希望它在div的顶部。如何解决这个问题?

HTML

<div class="div1" ng-click="hide()" ng-show="show" >
  CLICK ME
</div>


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

<div class="modal-header" ng-style="{'z-index': 99000}">
    <h4 class="modal-title">The Title</h4>
</div>
  SOME TEXT IN THE MODAL

</script>

的Javascript

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

    $scope.show = true;

    (function() {
          $scope.modalInstance = $uibModal.open({
              templateUrl: 'myModalContent.html'
            }); 


    })();


    $scope.hide = function(){
      $scope.show = false;
    };

});

CSS

.div1 {
  position: fixed;
  z-index: 90000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: blue;
}

3 个答案:

答案 0 :(得分:9)

为了完成这项工作,您必须为z-index属性创建自定义样式:

.zindex {
  z-index: 99000 !important;
}

将类应用于模态窗口:

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

示例:http://plnkr.co/edit/4T5Om0EcFAh5i4WUgNYi?p=preview

答案 1 :(得分:1)

尝试将z-index与相对位置结合使用。

<强> HTML

<div class="div1" ng-click="hide()" ng-show="show" >
  CLICK ME
</div>

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

<div class="modal-header" style="z-index: 99000; position:relative;">
    <h4 class="modal-title">The Title</h4>
</div>
  SOME TEXT IN THE MODAL

</script>

供参考:set Z index not working. button behind a container (HTML - CSS)

答案 2 :(得分:0)

尝试将z-index放在模态对话框而不是标题上,并使用modal-body:

<div class="div1" ng-click="hide()" ng-show="show" >
  CLICK ME
</div>


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

<div class="modal-dialog" style="z-index: 99000 !important">
    <div class="modal-header">
        <h4 class="modal-title">The Title</h4>
    </div>
    <div class="modal-body">
        SOME TEXT IN THE MODAL
    </div>
</div>
</script>