[英]CSS - My issues with width and alignment of Bootstrap select jQuery plugin
這可能是微不足道的做法,但我似乎無法處理。
我使用的是Twitter Bootstrap 3.3.6和jQuery 1.12.0,還使用了“ bootstrap-select” jQuery 插件 :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
</head>
<body>
<br>
<div>
<div class="panel panel-primary">
<div class="panel-heading ">
<center>
<select class="selectpicker" id="headingSelect">
<option>Item 1</option>
<option selected>Item 2</option>
<option>Item 3</option>
</select>
</center>
</div>
<div class="panel-body">
<center>
<div class="form-inline">
<div class="form-group">
<label class="control-label" for="age">Age:</label>
<input type="text" class="form-control" id="age" style="width:45px;">
</div>
<div class="form-group">
<label class="control-label" for="Month">Month:</label>
<select id="Month" class="selectpicker">
<option>Month1</option>
<option selected>Month2</option>
<option>Month3</option>
</select>
</div>
<div class="form-group">
<label for="Year">Year:</label>
<input type="text" class="form-control" id="Year" style="width:60px;">
</div>
</div>
</center>
</div>
</div>
</div>
</div>
</body>
</html>
我這里有兩個問題:
我希望選擇選項居中對齊,但我不能!
我也無法減小“月”輸入的大小!
請幫忙! 謝謝!
bootstrap-select的CSS看起來很笨拙,因此您必須以相當高的特異性進行覆蓋...因此,最簡單的方法是在div中添加一個ID來包裝月份選擇,以便您可以專門針對它。 (假設您不希望選擇的項目大小與您在month div上的自定義大小相同)。
如果您擅長添加ID,則需要以下其他CSS:
.dropdown-menu>li>a {
text-align:center;
}
#month-select .bootstrap-select.btn-group {width:auto;}
#month-select.bootstrap-select.btn-group .dropdown-toggle,
#month-select.bootstrap-select.btn-group .dropdown-menu {
max-width:100px; /* or whatever width you want the select and dropdown to be */
min-width:100px; /* or whatever width you want the select and dropdown to be */
}
/* if you want to center the label in the dropdown button, not just the options
in the list, uncomment this:
.bootstrap-select.btn-group .dropdown-toggle .filter-option {
text-align:center;
padding-left:12px
}
*/
Codepen: http ://codepen.io/anon/pen/KzOpGJ
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.