gpt4 book ai didi

html - Bootstrap 4 模态中心内容

转载 作者:太空狗 更新时间:2023-10-29 15:36:46 25 4
gpt4 key购买 nike

谁能解释一下如何在 Bootstrap 4 模式中水平居中标题。

我已经尝试过 text-centermx-automl-0/mr-0 但它们似乎没有工作。

这是一个 link到 fiddle 。

下面的代码;

<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>

最佳答案

modal-header 是 display:flex,因此居中其内容(如 modal-title)的工作方式不同。您可以使用 mx-auto,但居中是相对于关闭按钮而言的,因此它并不完全居中。

一种选择是使标题显示: block (d-block)并使用text-center

https://jsfiddle.net/44v0b25k/

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header d-block">
<button type="button" class="close float-right" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<h5 class="modal-title text-center" id="exampleModalLabel">Modal title</h5>
</div>
<div class="modal-body">
...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>

另一种选择是在 modal-title 上使用 w-100 使其全宽,并且 text-center 也可以.

<div class="modal-header">
<h5 class="modal-title w-100 text-center" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>

https://jsfiddle.net/306ob2e5/

关于html - Bootstrap 4 模态中心内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50041065/

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