【发布时间】:2021-04-11 00:24:42
【问题描述】:
我有一段 vh-100,有一个容器和两排。我试图让一行包含 2 个cols(标题、图像和下拉菜单)垂直对齐到容器的中间,另一行(i 标签)垂直对齐到底部。但是,这似乎不起作用。我曾尝试使用 Bootstrap 的 mt-auto 和 flex-column,但似乎都不起作用,我确信我的代码可能有问题,我将其附加在下面:
<section class="landing min-vh-100 d-flex align-items-center" id="landing">
<div class="container">
<div class="row"> #ROW 1 (to be vertically centered)
<div class="col-md-7 my-auto">
<h1 class="text-white display-3 mb-4">Text</h1>
<h3 class="text-white mb-4" id="example">Subtext</h3>
<div class="btn-group mr-1">
<button type="button" class="btn btn-lg btn-dark rounded-0 dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
Dropdown Menu
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Dropdown 1</a>
<a class="dropdown-item" href="#">Dropdown 2</a>
</div>
</div>
<a href="#" target="_blank" class="text-white font-weight-bold btn-lg">Link</a>
</div>
<div class="col-md-5 my-auto"><img src="#" class="img-fluid" alt=""></div>
</div>
<div class="row mt-auto"> #ROW 2 (to be vertically aligned to bottom)
<a href="#" class="pt-3 mx-auto"><i class="fas fa-chevron-circle-down text-light"></i></a>
</div>
</div>
我的猜测是,由于 section 标签上的 align-items-center,这些行可能居中。我尝试在第 1 行使用my-auto,在第 2 行使用mt-auto,但无济于事。如果有人能帮我解决这个问题,我将不胜感激。
【问题讨论】:
-
对你的问题很困惑,介意告诉我下拉菜单应该在哪里吗?第 1 行还是第 2 行?
-
是的,很抱歉。第 1 行包含 2 个列(一个列具有 h1、h3 和下拉菜单,另一个列包含图像)。我的目标是让第二行的 i 标签与容器底部对齐,第一行与中心对齐。使主要问题和代码更加清晰。
标签: html bootstrap-4 flexbox row