2014-09-23 53 views
1

如何將引導程序3.2中的水平表單居中? (相對於表格容器)。引導程序中的水平表單3

您可以在http://www.bootply.com/odXfJPlHRV

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div id="signup" style="width:800px;border:1px solid black"> 
 
<form class="form-horizontal no-margin center-block"> 
 
    <div class="form-group center-block"> 
 
     <label for="inputEmail" class="control-label col-xs-2">Email</label> 
 
     <div class="col-xs-2"> 
 
      <input type="email" class="form-control" id="inputEmail" placeholder="Email"> 
 
     </div> 
 
    </div> 
 
    <div class="form-group"> 
 
     <label for="inputPassword" class="control-label col-xs-2">Password</label> 
 
     <div class="col-xs-2"> 
 
      <input type="password" class="form-control" id="inputPassword" placeholder="Password"> 
 
     </div> 
 
    </div> 
 
    <div class="form-group last-form-group"> 
 
     <div class="col-xs-offset-2 col-xs-2"> 
 
      <button type="submit" class="btn btn-primary">Create an account</button> 
 
     </div> 
 
    </div> 
 
</form> 
 
</div>

+0

?該頁面,父div?寬度,高度,寬度和高度?更具體一些......並且,你嘗試了什麼? – henser 2014-09-23 12:41:33

+0

關於表單容器。 – Wesley 2014-09-23 12:41:55

+0

http://stackoverflow.com/questions/12172651/how-to-center-form-in-twitter-bootstrap – hakiko 2014-09-23 12:51:04

回答

1

交換班,.col-xs-2.col-xs-6

然後申請一個text-align: right;<label>text-align:left;並設置固定width<input>

如果你想添加標籤之間更多的空間 - 輸入添加col-xs-offset-*

檢查,看是否是預期的結果:

BOOTPLY DEMO

+0

不起作用,現在標籤從中心開始,但我希望以內容爲中心。 – Wesley 2014-09-23 12:50:26

+0

添加演示到OP ...檢查這是否是預期的結果 – henser 2014-09-23 13:00:27

1

進近時將使用col-*-offset-* classes將標籤和按鈕向右移動以使其居中 - Bootply example

在這種情況下,每個標籤和輸入都有.col-xs-2,那麼會有6列可用。因此,你可以使用col-xs-offset-3如下:關於什麼

<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"/> 
 
<div id="signup"> 
 
<form class="form-horizontal no-margin"> 
 
    <div class="form-group"> 
 
     <label for="inputEmail" class="control-label col-xs-offset-3 col-xs-2">Email</label> 
 
     <div class="col-xs-2"> 
 
      <input type="email" class="form-control" id="inputEmail" placeholder="Email"> 
 
     </div> 
 
    </div> 
 
    <div class="form-group"> 
 
     <label for="inputPassword" class="control-label col-xs-offset-3 col-xs-2">Password</label> 
 
     <div class="col-xs-2"> 
 
      <input type="password" class="form-control" id="inputPassword" placeholder="Password"> 
 
     </div> 
 
    </div> 
 
    <div class="form-group last-form-group"> 
 
     <div class="col-xs-offset-5 col-xs-2"> 
 
      <button type="submit" class="btn btn-primary">Create an account</button> 
 
     </div> 
 
    </div> 
 
</form> 
 
</div>

-1

<div class="row_fluid"> 
 
     <div class="span3">&nbsp; </div> 
 
     <div class="span6"> Add your form in here </div> 
 
     <div class="span3">&nbsp; </div> 
 
    </div>