gpt4 book ai didi

Angularjs UI Bootstrap : how to vertical center modal component?

转载 作者:行者123 更新时间:2023-12-02 21:59:43 25 4
gpt4 key购买 nike

最近在学习AngularJS。我之前用过bootstrap。使用 jquery,我可以轻松更改模态组件位置,使其垂直对齐。现在有了 AngularJS,似乎不太容易做到这一点。这是 ui bootstrap modal 的 plunker 链接,有人知道如何使其垂直对齐吗?

ui bootstrap modal component

1.index.html

    <!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.2.1.js"></script>
<script src="example.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="ModalDemoCtrl">
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header">
<h3 class="modal-title">I'm a modal!</h3>
</div>
<div class="modal-body">
This is modal body
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
<button class="btn btn-warning" type="button" ng-click="cancel()">Cancel</button>
</div>
</script>
<button type="button" class="btn btn-default" ng-click="open()">Open me!</button>
</div>
</body>
</html>

2.example.js

    angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function($scope, $uibModal, $log) {

$scope.items = ['item1', 'item2', 'item3'];

$scope.animationsEnabled = true;

$scope.open = function(size) {

var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller: 'ModalInstanceCtrl',
size: size,
resolve: {
items: function() {
return $scope.items;
}
}
});
};
});

angular.module('ui.bootstrap.demo').controller('ModalInstanceCtrl', function($scope, $uibModalInstance, items) {
$scope.ok = function() {
$uibModalInstance.close($scope.selected.item);
};

$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
});

最佳答案

如果我正确理解你的问题,你可以通过使用 CSS 来实现垂直居中对齐。添加以下 CSS:

.modal {
text-align: center;
padding: 0!important;
}

.modal::before {
content: '';
display: inline-block;
height: 100%;
vertical-align: middle;
margin-right: -4px;
}

.modal-dialog {
display: inline-block;
text-align: left;
vertical-align: middle;
}

我设置了 Plunker从你的 fork 出来进行演示。

您可以找到以下有用的链接

  1. Bootstrap 3 modal vertical position center
  2. Codepen Emaple

希望这有帮助。干杯!!

关于Angularjs UI Bootstrap : how to vertical center modal component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35693218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com