对齐项目中心,同时保持背景全高 [英] align-items-center while keeping the background full height
本文介绍了对齐项目中心,同时保持背景全高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Bootstrap 4的一行中有两列. 如果我尝试使用行上的align-items-center或col上的align-self-center垂直对齐内容,则h4居中,但背景不是全高. 这是一支笔 https://codepen.io/geo555/pen/PyaLbE
I have two columns inside a row in Bootstrap 4. If I try to align vertically the content using align-items-center on the row, or align-self-center on the col, the h4 is centered but the background is not full height. Here is a pen https://codepen.io/geo555/pen/PyaLbE
<div class="container">
<div class="row no-gutters justify-content-center">
<div class="col-sm-4">
<img src="https://via.placeholder.com/400X400" class="img-fluid">
</div>
<div class="col-sm-4 text-center bg-dark text-white align-self-center">
<h4>Awesome desk</h4>
</div>
</div>
</div>
推荐答案
使col d-flex flex-column
并在标题上使用垂直自动边距(my-auto
)...
Make the col d-flex flex-column
and use vertical auto margin (my-auto
) on the heading...
<div class="container">
<div class="row no-gutters justify-content-center">
<div class="col-sm-4">
<img src="https://via.placeholder.com/400X400" class="img-fluid">
</div>
<div class="col-sm-4 border text-center bg-dark text-white d-flex flex-column">
<h4 class="my-auto">Awesome desk</h4>
</div>
</div>
</div>
https://www.codeply.com/go/7nPpNbXHF4
这篇关于对齐项目中心,同时保持背景全高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文