垂直居中引导角模态窗口

use*_*227 3 css twitter-bootstrap angularjs bootstrap-modal angular-bootstrap

无论显示内容的大小如何,我如何都可以将该模式窗口垂直居中。在我的页面中,我将图像显示为模式窗口,并且希望将其显示在屏幕中央。我可以水平对齐,但不能使其垂直协作。有什么想法/例子吗?

我在页面中遵循以下示例:模态窗口演示插件

但模态窗口的实际内容如下所示:

<script type="text/ng-template" id="myModalContent.html">
        <div>
             <img class= "attachmentImage" src={{items}} />
        </div>
</script>
Run Code Online (Sandbox Code Playgroud)

我应该寻找使的变化bootstrap.min.css或者ui-bootstrap-tpls-0.13.0.js或者是在我自己的表与我的风格接近这一目标的最佳途径。

非常感谢您的宝贵时间。如果您需要更多信息或不清楚,请告诉我。

And*_*hiu 5

我强烈不同意1Bladesforhire的回答,因为modal当容器的顶部高于视口高度时,容器的顶部将变得不可访问。当使用absolute垂直居中方法将比父母高的孩子居中时,这是一个常见问题。

我首选的将Bootstrap模态垂直居中的方法是

.modal-dialog {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-y: auto;
  min-height: calc(100vh - 60px);
}
@media (max-width: 767px) {
  .modal-dialog {
    min-height: calc(100vh - 20px);
  }
}

/* you only need the above CSS. The code below centers the modal trigger button */

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

垂直居中时(小于视口宽度),.modal-content即使高度为,也仍然可以完全访问300vh

.modal-dialog {
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow-y: auto;
  min-height: calc(100vh - 60px);
}
@media (max-width: 767px) {
  .modal-dialog {
    min-height: calc(100vh - 20px);
  }
}

/* you only need the above CSS. The code below centers the modal trigger button */

.modal-content {
  height: 300vh;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
Run Code Online (Sandbox Code Playgroud)
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)