我有一個引導窗體,其中兩個域添加了類.d-inline-block
,這樣它就會彼此相鄰,並且我還有另一個域,我沒有添加該類以便它來低於兩個字段。引導窗體不在div的中心
我希望這是在我無法做到的div的中心。只有前兩個字段纔會居中,而不是最後一個div。
有人能指出錯誤嗎?
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css');
.d-inline-block {
width: 40%;
}
.message {
width: 80%;
}
.formClass {
margin-left: auto !important;
margin-right: auto !important;
text-align: center;
}
<form class="formClass ">
<div class="form-group d-inline-block">
<input type="text" class="form-control" id="nameInput">
<div class="form-control-placeholder"> Name </div>
</div>
<div class="form-group d-inline-block">
<input type="text" class="form-control" id="phoneInput">
<div class="form-control-placeholder"> Phone </div>
</div>
<div class="form-group message">
<input type="text" class="form-control" id="phoneInput">
<div class="form-control-placeholder"> Phone </div>
</div>
</form>
https://jsfiddle.net/97avbgsq/
正如你所說'水平居中的塊元件的寬度,使用保證金左:汽車; margin-right:auto'我已經使用過它,但爲什麼你需要額外的'margin-auto'作爲消息輸入元素? – Rehan
@ this.Believer您必須將寬度和邊距分配給相同的元素。 '.message'上的寬度爲80%,'.formClass'上的margin爲自動。 –