我试图在 Bootstrap 4 (4.0.0-alpha.6) 中将我的大屏幕的内容垂直对齐在中心。在 Mac 桌面上的 Chrome 和 Safari 中,这种情况发生得很好,但在我的 iOS 设备上则不然,文本仍然与顶部对齐。
我强制大屏幕显示得比最小高度高,以容纳背景图片。
这是 HTML...
<!-- jumbotron -->
<div class="jumbotron jumbotron-fluid mb-0 cxt-bg-dark-grey cxt-bgimg-frame cxt-bgimg-tint cxt-bgimg-cook text-white text-center" style="min-height:500px"> <!-- .jumbotron-fluid and content in .container make jumbotron full-width and squared corners, cf. https://v4-alpha.getbootstrap.com/components/jumbotron/ -->
<div class="container">
<div class="row">
<div class="col-md-12 cxt-title">
<h1 class="display-4 pb-2">Jumbotron title</h1>
<p class="lead pb-4">Sub-title sub-title sub-title v sub-title sub-title sub-title sub-title </p>
<a class="btn btn-primary pmd-ripple-effect btn-lg mb-4" href="#" role="button">Get Started</a>
</div>
</div>
</div>
</div>
这是CSS...
.cxt-bgimg-frame {
width:100%;
height:100%;
height:calc(100% - 1px);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
display: flex;
align-items: center;
}
.cxt-bgimg-tint {
background-color: rgba(10,10,10,0.6);
background-blend-mode: multiply;
}
.cxt-bgimg-cook {
background-image:url('path/to/my/image.png');
}
关键部分是...
display: flex;
align-items: center;
正如我所说,它在桌面上运行良好,但在 iOS 设备(如我的 iPad)上运行不佳。
我还尝试添加一些 webkit 引用......
.cxt-bgimg-frame {
width:100%;
height:100%;
height:calc(100% - 1px);
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-ms-flex-align: center;
-webkit-align-items: center;
-webkit-box-align: center;
align-items: center;
}
...但这并不能解决问题。
我知道,根据发布文档,从 Bootstrap 4.0.0 alpha 6 开始,“Bootstrap 4 现在默认是 Flexbox!”但我不知道这是否消除了我调用上面的 Flex 内容的需要。
如何正确地使事物在中心垂直对齐?
解决方案应该是一个以 Bootstrap 4 为中心的解决方案。