html - 如何在 Bootstrap 4 中的图像覆盖卡上垂直对齐?
问题描述
我试图将 FontAwesome 图标置于图像叠加卡的中心,但无法垂直居中。
我尝试了多种其他建议,例如使用d-flex
,justify-content-center
但似乎都没有。我错过了什么?
<head>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
</head>
<body>
<div class="card bg-dark text-white">
<img class="card-img" src="http://placehold.jp/500x200.png" alt="Example">
<div class="card-img-overlay text-center">
<i class="fab fa-youtube fa-5x" style="color:#FF0000"></i>
</div>
</div>
</body>
我希望图标在图像中间居中,但只能水平对齐而不是垂直对齐。谢谢您的帮助。
解决方案
您可以将d-flex
类添加到.card-img-overlay
元素,然后添加class="align-self-center mx-auto"
到内部a
元素:
<div class="card bg-dark text-white">
<img class="card-img" src="images/example.jpg" alt="Example">
<div class="card-img-overlay d-flex">
<a class="align-self-center mx-auto" data-fancybox href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">
<i class="fa fa-youtube fa-5x zoom" style="color:#FF0000"></i>
</a>
</div>
</div>
align-self-center
有关官方 BS4 文档的更多信息: https ://getbootstrap.com/docs/4.3/utilities/flex/#align-self
推荐阅读
- python - tf-idf 向量空间中的 ntc 形式到底是什么?
- javascript - 量角器:e2e:魅力报告:allure.createStep 问题
- rust - 注意文件删除和重新创建
- javascript - 在不同位置具有不同“slidesToShow”的光滑轮播
- ios - 弹出 UIViewController 后如何防止调用通知观察者?
- sqlite - 为 2 列选择一个匹配项
- wpf - 如何使用 List 填充文本块?
- jsf - 带有 Tomahawk-Savestate 自己的 savestate 组件的 JSF 1.2 到 JSF 2.3?
- python - AWS SageMaker TensorFlow RNN 训练花费大量时间
- microsoft-edge - 强制 Edge 不自动翻译内容