html - 在 Bootstrap 轮播中垂直居中 div
问题描述
我有以下结构:
<div class="carousel" id="my-carousel">
<div class="carousel-item">
<div class="text-center">
...
</div>
</div>
<div class="carousel-item">
<div class="text-center">
...
</div>
</div>
<div class="carousel-item">
<div class="text-center">
...
</div>
</div>
</div>
我还有以下用于标准化轮播的脚本:
function normalizeCarousel() {
function normalize() {
var maxHeight = 0;
$(".carousel-item").each(function() {
var currentHeight = $(this).height();
if (currentHeight > maxHeight) {
maxHeight = currentHeight;
}
});
$("#my-carousel").css("height", maxHeight);
};
normalize();
$(window).on("resize orientationchange", function() {
normalize();
});
}
$(document).ready(function() {
normalizeCarousel();
});
这是 JSFiddle:JSFiddle
我想要做的是垂直text-center
对齐carousel-items
. 我试过使用flexbox
但无法让它工作!
先感谢您!
解决方案
这应该可以解决问题
.carousel-item {
display: table;
}
.text-center {
display: table-cell;
vertical-align:middle;
}
推荐阅读
- ruby-on-rails - 从 Cedar14 到 heroku18 的 Ruby 更新堆栈
- http - 如果我不需要响应,是否需要 resp.Body.Close()?
- anaconda - 蟒蛇/ Spyder4.1.1
- c# - 在计算接触法线和穿透深度时,有时会在 EPA 算法中进入无限循环
- python - 按星期排序 - Django
- php - Laravel bcrypt 质量分配
- c++ - 如何使用输入来终止 C++ 中的程序?
- ios - 在不启动主应用程序的情况下运行 Widget-extension
- docker - 分子:测试角色:无法获得 Dbus 连接操作不允许
- powershell - Connect-VIServer 无法连接,因为证书无效,无视 PowerCLI 的配置