gpt4 book ai didi

html - bootstrap flex 不让内容居中

转载 作者:行者123 更新时间:2023-11-28 19:19:59 25 4
gpt4 key购买 nike

bootstrap flex 不让内容居中

<div class="d-flex flex-row bd-highlight mb-3">
<div class="p-2 bd-highlight text-left"><i class="fa fa-chevron-left" aria-hidden="true"></i></div>
<div class="p-2 bd-highlight text-muted text-center justify-content-center" style="text-transform: uppercase;">comments</div>
<div class="p-2 bd-highlight">Flex item 3</div>
</div>

我正在使用 bootstrap 4,不知何故类 text-center justify-content-center 不起作用,有人可以帮忙吗?

最佳答案

Bootstrap 4 justify classes需要应用于(使用 d-flex 类),而不是列。

justify-content-center 转移到父级,让您的元素按预期居中。

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="d-flex flex-row bd-highlight mb-3 justify-content-center">
<div class="p-2 bd-highlight text-left"><i class="fa fa-chevron-left" aria-hidden="true"></i></div>
<div class="p-2 bd-highlight text-muted" style="text-transform: uppercase;">comments</div>
<div class="p-2 bd-highlight">Flex item 3</div>
</div>

请注意,这会使所有元素居中。如果您正在寻找“左-中-右”布局(以便只有中间元素居中),那么您需要 justify-content-between 代替:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<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.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<div class="d-flex flex-row bd-highlight mb-3 justify-content-between">
<div class="p-2 bd-highlight text-left"><i class="fa fa-chevron-left" aria-hidden="true"></i></div>
<div class="p-2 bd-highlight text-muted" style="text-transform: uppercase;">comments</div>
<div class="p-2 bd-highlight">Flex item 3</div>
</div>

关于html - bootstrap flex 不让内容居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57518272/

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