[英]how to horizontally align label and select tags in bootstrap 3?
問題是labels
和select tags
之間的差距很大
<form class="form-horizontal">
<fieldset>
<div class="row">
<div class="form-group">
<label class="col-sm-4 contro-label ">What Skill will you be working on?</label>
<div class="col-sm-3">
<select class="form-control input-sm">
<option>Select</option>
<option>PHP</option>
<option>JAVA</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 contro-label">What Course?</label>
<div class="col-sm-3">
<select class="form-control input-sm">
<option>Select</option>
<option>CMP</option>
<option>IT</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 contro-label">Section?</label>
<div class="col-sm-3">
<select class="form-control input-sm">
<option>Select</option>
<option>34432</option>
<option>44333</option>
</select>
</div>
</div>
</div>
</fieldset>
</form>
我試圖row
添加一些col-sm-x
但是沒有用。 這是有關其外觀的圖像:
我也嘗試在標簽中添加pull-right
類,但是由於label
和select tag
在同一form-group
所以我認為這導致所有內容移到了不正確的位置
使用.form-horizontal
,每個.control-label
子級將右對齊以獲取sm
及更多內容。
因此,更正.control-label
應該足夠了。
但是,由於沒有指定應如何呈現較小分辨率的指示,因此可以添加.text-right
來保持正確的對齊方式,而與分辨率無關。
這是一個Bootply,使它更易於查看: http : //www.bootply.com/LtdAfSi0B3
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet"/> <link href="http://getbootstrap.com/dist/css/bootstrap-theme.min.css" rel="stylesheet"/> <script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="http://getbootstrap.com/dist/js/bootstrap.min.js"></script> <form class="form-horizontal"> <div class="form-group"> <label class="col-sm-4 control-label text-right">What Skill will you be working on?</label> <div class="col-sm-3"> <select class="form-control input-sm"> <option>Select</option> <option>PHP</option> <option>JAVA</option> </select> </div> </div> <div class="form-group"> <label class="col-sm-4 control-label text-right">What Course?</label> <div class="col-sm-3"> <select class="form-control input-sm"> <option>Select</option> <option>CMP</option> <option>IT</option> </select> </div> </div> <div class="form-group"> <label class="col-sm-4 control-label text-right">Section?</label> <div class="col-sm-3"> <select class="form-control input-sm"> <option>Select</option> <option>34432</option> <option>44333</option> </select> </div> </div> </form>
您忘記了L : <label class="col-sm-4 contro-label">
到<label class="col-sm-4 control-label">
它會神奇地對齊;)
通過為標簽指定col-sm-4
類,您將迫使它們占用其容器的三分之一。 嘗試將其減少為col-sm-3
或col-sm-2
。
記住要查看表單在不同瀏覽器尺寸下的外觀。 您可能還需要指定一些col-xs-*
col-md-*
col-xs-*
, col-md-*
和col-lg-*
類,以確保在不同的瀏覽器尺寸下按需要顯示表單。 有關更多詳細信息,請參見此處 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.