垂直对齐列中间文本的最佳/正确方法是什么?图片高度在 CSS 中静态设置。
我已经尝试将外部 div 设置为 display: table
并将内部 div 设置为 display: table-cell
和 vertical-align: middle
但这也不起作用。
HTML
<section id="browse" class="browse">
<div class="container">
<div class="row">
<div class="col-md-5 col-sm-5">
<h2 class="text-left">Link up with other gamers all over the world who share the same tastes in games.</h2>
</div>
<div class="col-md-1"></div>
<div class="col-md-6 col-sm-7 animation_container">
<img id="animation_img2" class="animation_img animation_img2" src="images/section2img2.png"/>
<img id="animation_img1" class="animation_img animation_img1" src="images/section2img1.png"/>
</div>
</div>
</div>
</section>
CSS
.browse .container, .blind_dating .container { padding-bottom: 0; }
.animation_container { position: relative; }
.browse .animation_container { height: 430px; }
.animation_img { position: absolute; bottom: 0; }
.animation_img1 { right: 25%; }
.animation_img2 { right: 25%; }
最佳答案
HTML:
首先,我们需要向您的文本容器添加一个类,以便我们可以相应地访问它并为其设置样式。
<div class="col-xs-5 textContainer">
<h3 class="text-left">Link up with other gamers all over the world who share the same tastes in games.</h3>
</div>
CSS:
接下来,我们将根据旁边图像 div 的大小应用以下样式使其垂直对齐。
.textContainer {
height: 345px;
line-height: 340px;
}
.textContainer h3 {
vertical-align: middle;
display: inline-block;
}
全部完成!如果您认为上面的样式仍然稍微不对齐,请调整行高和高度。
关于html - Bootstrap 如何让文本在 div 容器中垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25538732/