在 Bootstrap 5 中将 div 置于其他 div 之下
Centering a div under other divs in Bootstrap 5
我有一些基本的 HTML(零 CSS),旨在在页面顶部显示标题,然后在中间显示一段文字。这是我的代码:
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="d-flex flex-column min-vh-100">
<h1 class="text-center my-4">Title</h1>
<div class="d-flex flex-grow-1 justify-content-center align-items-center">
<div>Centered!</div>
</div>
</div>
</div>
但是,顶部的 div 似乎偏移了中间的位置(我希望中间的在页面居中)。感谢您的帮助,我是新手!
一个解决方案是将 fixed-top 添加到 h1。这样它就停止消耗垂直 space.
见下文:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="container-fluid">
<h1 class="text-center my-4 fixed-top">Title</h1>
<div class="d-flex flex-column min-vh-100">
<div class="d-flex flex-grow-1 justify-content-center align-items-center">
<div>Centered!</div>
</div>
</div>
</div>
我有一些基本的 HTML(零 CSS),旨在在页面顶部显示标题,然后在中间显示一段文字。这是我的代码:
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="d-flex flex-column min-vh-100">
<h1 class="text-center my-4">Title</h1>
<div class="d-flex flex-grow-1 justify-content-center align-items-center">
<div>Centered!</div>
</div>
</div>
</div>
但是,顶部的 div 似乎偏移了中间的位置(我希望中间的在页面居中)。感谢您的帮助,我是新手!
一个解决方案是将 fixed-top 添加到 h1。这样它就停止消耗垂直 space.
见下文:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<div class="container-fluid">
<h1 class="text-center my-4 fixed-top">Title</h1>
<div class="d-flex flex-column min-vh-100">
<div class="d-flex flex-grow-1 justify-content-center align-items-center">
<div>Centered!</div>
</div>
</div>
</div>