The modal-header
is display:flex so centering its' content (like the modal-title
) works differently. You can use mx-auto
but then centering is relative to the close button so it's not exactly centered.
One option is to make the header display:block (d-block
) and use 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">×</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>
Another option is to use w-100
on the modal-title
so that it's full width, and text-center
will also work.
<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">×</span>
</button>
</div>
https://jsfiddle.net/306ob2e5/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…