gpt4 book ai didi

html - Bootstrap 4 - 在 flexbox 子容器上对齐内容中心(覆盖 flex 父容器)

转载 作者:行者123 更新时间:2023-11-27 23:05:24 25 4
gpt4 key购买 nike

使用 Bootstrap 4,我试图将 img 居中放置在主 div 的底部中间。然而,它并不居中。

应该是这样的: enter image description here

<!doctype html>
<html lang="en">
<head>
<title>Hello, world!</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css">


<style>

section.masthead2{
background-color:orange;
background-repeat: no-repeat;
background-attachment: scroll;
background-position: center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
height:80vh;
}
.gear {
height: 50px;
}
.botonhome{
background-color:#eb6626;
color: #ffffff;
padding-left:2em;
padding-right:2em;
font-family:'Josefin Sans', sans-serif;
font-weight:500;
border-radius:0.5em;
font-size:1.2em;
}
</style>

</head>
<body>
<section class="container-fluid masthead2 d-flex align-items-center justify-content-center">
<div class="row">
<div class="col-12 d-flex justify-content-center">
<h1 class="textoprincipal ">Lorem Ipsum is simply dummy text of the printing</h1>
</div>
<div class="col-12 d-flex justify-content-center">
<a class="btn botonhome mr-3" routerLink="/backoffice/job" routerLinkActive="active" role="button">Testing1</a>
<a class="btn botonhome" routerLink="/backoffice/jobs" routerLinkActive="active" role="button">Testing2</a>
</div>
</div>
<div class="row d-flex align-self-end ">
<div class="col-12">
<img class="gear text-center" src="https://upload.wikimedia.org/wikipedia/commons/1/13/Cog%2C_Web_Fundamentals.svg">
</div>
</div>
</section>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
<script src="js/bootstrap.min.js"></script>
<!-- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script> -->
</body>
</html>

由于主容器流体具有 d-flex,因此两个后续的 div 行水平并排放置。下面是在主容器流体中没有 d-flex 时的样子(使用背景颜色来区分齿轮) enter image description here

在主容器流体中应用 d-flex 后(因为我需要对齐并证明主标题和按钮居中),由于主容器中的 d-flex,齿轮图标图像位于左 Angular 。 enter image description here我如何从它的主要容器流体中覆盖这个元素 d-block,这样我就可以将它移动到 div 的 bootom 中间?这可以通过 Bootstrap 类实现吗?

我不能制作两个主要的流体容器,因为背景将是图像。

最佳答案

现在我已经用 img 标签发布了答案...请检查...

我已经发布了答案,但您想将其更改为与您在 img 标签中给定的类(class)相对应的类(class)。

注意:下面的代码片段是 Button 标签的示例。在您的情况下,将其更改为 img。现在我在下面的例子中也包含了 img 标签

 .gear {
height: 50px;
position:absolute;
margin-left:50%;
margin-right:50%;
transform: translateX(-50%);
}
<img class="gear" src="http://www.clker.com/cliparts/2/5/7/f/1297719143988960365gear_red.png" style="width:50px;height:50px;"/>

关于html - Bootstrap 4 - 在 flexbox 子容器上对齐内容中心(覆盖 flex 父容器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49766379/

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