css - 如何在给定高度将引导程序 4 中的容器居中?
问题描述
我想在引导程序 4 中居中一个容器。我有一个宽度为 300px 的元素,
.guide-background{
background: url("https://www.webascender.com/wp-content/uploads/executive-guide-1.jpg");
background-repeat: no-repeat;
background-size: cover;
height: 350px;
/*filter: brightness(50%);*/
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<section id="guide" class="guide-background">
<!-- I want to center this container with id #center_it -->
<div class="container border border-danger" id="center_it">
<div class="row">
<div class="col align-self-center">
<h2 class="text-center"> <a href="" class="">Center Me</a></h2>
</div>
</div>
</div>
</section>
然后我在里面放了一个容器,然后怎么可能把容器放在里面。我试着用网格系统来做。但我失败了。真的需要帮助
解决方案
您可以flex
为此使用 display,Bootstrap 已在https://getbootstrap.com/docs/4.0/utilities/flex/
.guide-background {
background: url("https://www.webascender.com/wp-content/uploads/executive-guide-1.jpg");
background-repeat: no-repeat;
background-size: cover;
height: 350px;
/*filter: brightness(50%);*/
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<section id="guide" class="guide-background d-flex align-items-center flex-colum">
<!-- I want to center this container with id #center_it -->
<div class="container border border-danger" id="center_it">
<div class="row n">
<div class="col align-self-center ">
<h2 class="text-center"> <a href="" class="">Center Me</a></h2>
</div>
</div>
</div>
</section>
推荐阅读
- c++ - 无与伦比的井字游戏
- qt - 无法连接 doublespinbox valuechanged 信号
- vb.net - 异常不会做它应该做的事情
- angular - 如何在 Angular App 中使用来自 cdns 的 moment.js
- embedded-linux - Iotivity 客户端在一段时间后未发现资源
- office-js - 使用 Word Javascript API 的自定义列表
- typescript - 将 DPAPI 与 Typescript 一起使用?
- google-sheets - 谷歌电子表格自动将时间转换为当前时区
- android - Android 应用程序让特定用户访问它
- c# - 无法在本地运行 Cosmos DB 更改源触发 Azure 函数