gpt4 book ai didi

css - bootstrap 4 中的垂直对齐

转载 作者:技术小花猫 更新时间:2023-10-29 11:29:19 25 4
gpt4 key购买 nike

我试图在图像上放置一个居中文本。我用过 mx-auto水平居中我的叠加文本并使用 align-middle用于垂直对齐。但是垂直对齐不起作用。有人知道为什么吗?

  

<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>

<div class="card ">
<img class="img-fluid card-img" src="https://snap-photos.s3.amazonaws.com/img-thumbs/960w/1U2EGZ07GU.jpg" alt="Deer in nature">
<div class="card-img-overlay d-flex">
<div class="mx-auto">
<h4 class="card-title align-middle">Animal Farm</h4>
<h6 class="text align-middle">George Orwell</h6>
<p class="card-text align-middle">Tired of their servitude to man, a group of farm animals revolt and establish their own society...</p>
</div>
</div>
</div>

最佳答案

只需将 my-auto 用于垂直中心...

  <div class="card">
<img class="img-fluid card-img" src="https://snap-photos.s3.amazonaws.com/img-thumbs/960w/1U2EGZ07GU.jpg" alt="Deer in nature">
<div class="card-img-overlay d-flex">
<div class="my-auto mx-auto text-center">
<h4 class="card-title">Animal Farm</h4>
<h6 class="text">George Orwell</h6>
<p class="card-text">Tired of their servitude to man, a group of farm animals revolt and establish their own society...</p>
</div>
</div>
</div>

http://codeply.com/go/ZQM4ANFcXC

align-middle 将适用于 display: tabledisplay: inline 元素。

另见 similar question

关于css - bootstrap 4 中的垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43313090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com