[英]Boostrap v4.0.0-alpha.6 model - how to center model title
您如何使模型的標題居中? 我厭倦了將類“text-center”添加到 h1 標簽,但它一直顯示磁貼左對齊。
謝謝
您可以在h3.modal-title
元素上使用w-100
類以及text-center
。
<div class="modal-header text-center">
<h3 class="modal-title w-100">Quiz Results</h3>
</div>
我今天必須弄清楚這一點,特別是當我想要在modal-title
中居中的模態modal-header
時 - 嘗試了幾種不同的方式,但這是我確定的:
<div class='modal-dialog' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<h3 class='col-12 modal-title text-center'>
Centered Modal Title
<button type='button' class='close' data-dismiss='modal' aria-label='Close'>
<span aria-hidden='true'>×</span>
</button>
</h3>
</div>
</div>
</div>
如果您想在“modal-header”標簽內進行操作,關鍵是col-12
。
這個問題在這里有詳細的答案
只需將w-100屬性值添加到類屬性即可。 那是:
<div class="modal-header">
<h5 class="modal-title w-100 text-center">Contact us via Email</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<h3 class="modal-title w-100 text-center">I'm centered title</h3>
嘗試更改模態標題
.modal-header{
justify-content: center;
}
Sava 方法對我有用。 另一種方法是添加“margin: 0 auto;” 對於您用於標題的任何 css 類。 例如,如果您使用模態標題,請添加到您的 css:
.modal-title {
margin: 0 auto;
}
您還可以將這些類添加到 modal-header
.ml-auto.mr-汽車
<div class="modal-header ml-auto mr-auto">
<h5 class="modal-title" id="exampleModalLongTitle">Model Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
是的 CSS 就足夠了,即使在 bootstrap vue 中也是如此:
<b-modal id="mymodal" title="My Modal">
您只需:
.modal-title{
width: 100%;
text-align: center;
}
在你的 css 文件中讓它居中。
試試style="margin: 0 auto;"
像<h5 class="modal-title" style="margin: 0 auto;">title</h5>
它工作正常!
要使標題居中並保留關閉按鈕,您可以這樣做:
<div class="modal-header pl-0">
<h5 class="modal-title w-100 text-center position-absolute">Title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
只需在模態標題 div 中添加.justify-content-center
類:
<div class="modal-header justify-content-center">
//your content here
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.