2015-04-02 132 views
1

我正在嘗試構建表單組,但它們未與Bootstrap 3正確對齊。Bootstrap 3表格未正確對齊

我試圖將它們垂直對齊。這是給我的噩夢所以需要一些對你有幫助

請參見下面的屏幕截圖

Form not alligning

下面是形式

 <div class="container"> 
     <h1>Edit Profile</h1> 
     <hr> 
     <div class="row"> 
      <!-- left column --> 
      <div class="col-md-3"> 
      <div class="text-center"> 
       <img src="//placehold.it/100" class="avatar img-circle" alt="avatar"> 
       <h6>Upload a different photo...</h6> 

       <input type="file" class="form-control"> 
      </div> 
      </div> 

      <!-- edit form column --> 
      <div class="col-md-9 personal-info"> 
<!--   <div class="alert alert-info alert-dismissable"> 
       <a class="panel-close close" data-dismiss="alert">×</a> 
       <i class="fa fa-coffee"></i> 
       This is an <strong>.alert</strong>. Use this to show important messages to the user. 
      </div> --> 
      <h3>Personal info</h3> 

      <form class="form-horizontal" role="form"> 

       <div class="form-group"> 
       <label class="col-lg-3 control-label">First name:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value="Jane"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Last name:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value="Bishop"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Company:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value=""> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Email:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value="[email protected]"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Time Zone:</label> 
       <div class="col-lg-8"> 
        <div class="ui-select"> 
        <select id="user_time_zone" class="form-control"> 
         <option value="Hawaii">(GMT-10:00) Hawaii</option> 
         <option value="Alaska">(GMT-09:00) Alaska</option> 
         <option value="Pacific Time (US &amp; Canada)">(GMT-08:00) Pacific Time (US &amp; Canada)</option> 
         <option value="Arizona">(GMT-07:00) Arizona</option> 
         <option value="Mountain Time (US &amp; Canada)">(GMT-07:00) Mountain Time (US &amp; Canada)</option> 
         <option value="Central Time (US &amp; Canada)" selected="selected">(GMT-06:00) Central Time (US &amp; Canada)</option> 
         <option value="Eastern Time (US &amp; Canada)">(GMT-05:00) Eastern Time (US &amp; Canada)</option> 
         <option value="Indiana (East)">(GMT-05:00) Indiana (East)</option> 
        </select> 
        </div> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label">Username:</label> 
       <div class="col-md-8"> 
        <input class="form-control" type="text" value="janeuser"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label">Password:</label> 
       <div class="col-md-8"> 
        <input class="form-control" type="password" value="11111122333"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label">Confirm password:</label> 
       <div class="col-md-8"> 
        <input class="form-control" type="password" value="11111122333"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label"></label> 
       <div class="col-md-8"> 
        <input type="button" class="btn btn-primary" value="Save Changes"> 
        <span></span> 
        <input type="reset" class="btn btn-default" value="Cancel"> 
       </div> 
       </div> 

      </form> 
      </div> 
     </div> 
    </div> 
    <hr> 

我的CSS片

代碼
/* CSS declarations go here */ 

.stylish-input-group .input-group-addon{ 
    background: white !important; 
} 
.stylish-input-group .form-control{ 
    border-right:0; 
    box-shadow:0 0 0; 
    border-color:#ccc; 
} 
.stylish-input-group button{ 
    border:0; 
    background:transparent; 
} 

.navbar .navbar-nav { 
    display: inline-block; 
    float: none; 
} 

.navbar .navbar-collapse { 
    text-align: center; 
} 



* { 
    margin-bottom: 0px; 
    margin-top:0px; 
    margin-right: 0px; 
    margin-left: 0px; 
} 

.bg{ 
    background: url(fundog.jpg); 
    background-size: cover; 
    color: white; 
    height: 500px; 
    margin-bottom: 0px; 
    margin-top:0px; 
} 
.navbar{ 
    margin-bottom: 0px; 
    margin-top:0px; 


} 
.help{ 
    text-align: right; 
    margin-bottom: 0px; 
    height: 300px; 

} 

.spread{margin-bottom: 0px;} 

body { 

    /* set this equal to navbar's height */ 
} 

.usp{ 
    text-align: center; 
} 

.row { 
    display: table; 
} 

[class*="col-"] { 
    float: none; 
    display: table-cell; 
    vertical-align: top; 
} 

.profile{ 
    margin-bottom: 100px; 
    margin-top:30px; 
    margin-right: 100px; 
    margin-left: 100px; 
} 
+0

我認爲你的窗體組裏的引導類應該加起來等於12嗎? ,因爲我發現你正在使用col-lg-3和col-lg-8 – Katrin 2015-04-02 10:44:50

+0

嗨,所以我需要使用col-lg-3和col-lg-9? – 2015-04-02 10:47:41

+0

@Tomchan是啊...你需要使用col-lg-3和col-lg-9,並且將列類放在'div' **而不是**標籤上 – Junaid 2015-04-02 10:50:57

回答

0

自己的CSS是造成問題:

[class*="col-"] { 
    float: none; 
    display: table-cell; 
    vertical-align: top; 
} 

具體來說,您的float:nonedisplay: table-cell組合。刪除它們並讓bootstrap將它們放在平常的位置。

也不確定是否將所有邊距設置爲零。不管喜不喜歡,Bootstrap都利用負邊距來正確佈局其中的一些類。

+0

謝謝,解決了它, – 2015-04-02 13:52:35

+0

ok會重新獲得保證金 – 2015-04-02 13:52:47

0

以下是有你的更新版本r標題,並且所有列都垂直內聯。

http://www.bootply.com/b38G8GZgjw

這裏是萬一bootply代碼不可用:

<div class="container"> 
     <h1>Edit Profile</h1> 
     <hr> 
     <div class="row"> 
      <!-- left column --> 
      <div class="col-md-3"> 
      <div class="text-center"> 
       <img src="//placehold.it/100" class="avatar img-circle" alt="avatar"> 
       <h6>Upload a different photo...</h6> 

       <input type="file" class="form-control"> 
      </div> 
      </div> 

      <!-- edit form column --> 
      <div class="col-md-9 personal-info"> 
<!--   <div class="alert alert-info alert-dismissable"> 
       <a class="panel-close close" data-dismiss="alert">×</a> 
       <i class="fa fa-coffee"></i> 
       This is an <strong>.alert</strong>. Use this to show important messages to the user. 
      </div> --> 
      <div class="row"> 
      <h3 class="col-lg-3 text-right">Personal info</h3> 
      </div> 

      <form class="form-horizontal" role="form"> 

       <div class="form-group"> 
       <label class="col-lg-3 control-label">First name:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value="Jane"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Last name:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value="Bishop"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Company:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value=""> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Email:</label> 
       <div class="col-lg-8"> 
        <input class="form-control" type="text" value="[email protected]"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-lg-3 control-label">Time Zone:</label> 
       <div class="col-lg-8"> 
        <div class="ui-select"> 
        <select id="user_time_zone" class="form-control"> 
         <option value="Hawaii">(GMT-10:00) Hawaii</option> 
         <option value="Alaska">(GMT-09:00) Alaska</option> 
         <option value="Pacific Time (US &amp; Canada)">(GMT-08:00) Pacific Time (US &amp; Canada)</option> 
         <option value="Arizona">(GMT-07:00) Arizona</option> 
         <option value="Mountain Time (US &amp; Canada)">(GMT-07:00) Mountain Time (US &amp; Canada)</option> 
         <option value="Central Time (US &amp; Canada)" selected="selected">(GMT-06:00) Central Time (US &amp; Canada)</option> 
         <option value="Eastern Time (US &amp; Canada)">(GMT-05:00) Eastern Time (US &amp; Canada)</option> 
         <option value="Indiana (East)">(GMT-05:00) Indiana (East)</option> 
        </select> 
        </div> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label">Username:</label> 
       <div class="col-md-8"> 
        <input class="form-control" type="text" value="janeuser"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label">Password:</label> 
       <div class="col-md-8"> 
        <input class="form-control" type="password" value="11111122333"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label">Confirm password:</label> 
       <div class="col-md-8"> 
        <input class="form-control" type="password" value="11111122333"> 
       </div> 
       </div> 
       <div class="form-group"> 
       <label class="col-md-3 control-label"></label> 
       <div class="col-md-8"> 
        <input type="button" class="btn btn-primary" value="Save Changes"> 
        <span></span> 
        <input type="reset" class="btn btn-default" value="Cancel"> 
       </div> 
       </div> 

      </form> 
      </div> 
     </div> 
    </div> 
+0

它仍然不能正常工作,也許我現在的CCS工作表正在搞亂它。 – 2015-04-02 13:29:00

+0

剛上傳了 – 2015-04-02 13:30:00