如何在select2下拉列表中实现input-lg类?我的下拉菜单与输入元素的大小相同,这里有一类输入-lg,这是我到目前为止所拥有的
<div class="col-sm-4">
<label for="mobile" class="control-label"><span class="text-danger">*</span> Nationality</label>
<input type="text" id="nationality" name="nationality" class="form-control input-lg" />
</div>
<div class="col-sm-4 padding-minimum">
<label for="mobile" class="control-label"><span class="text-danger">*</span> Gender</label>
<select name="gender" id="gender" class="form-control select2-container input-lg step2-select" data-placeholder="Select Gender">
<option></option>
<option value="1">Male</option>
<option value="0">Female</option>
</select>
</div>
这是我的剧本
<script>
$(document).ready(function(){
$('select').select2();
});
</script>
但似乎初始化下拉列表的大小与输入-lg类的输入字段的大小不同,尽管我在select元素上放置了一个input-lg类。有关如何实现这一点的任何想法?我只是希望select2与输入字段具有相同的高度
我使用select2版本4.0.0而css是版本3.5.2我认为
答案 0 :(得分:4)
要使select
输入的高度相等,请在CSS中进行以下更改,并从input-lg
移除<select>
选择器,这是不必要的,不使用它
$(document).ready(function () {
$('select').select2();
});
.select2-container--default .select2-selection--single {
height: 46px !important;
padding: 10px 16px;
font-size: 18px;
line-height: 1.33;
border-radius: 6px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow b {
top: 85% !important;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height: 26px !important;
}
.select2-container--default .select2-selection--single {
border: 1px solid #CCC !important;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.css" />
<div class="col-sm-4">
<label for="mobile" class="control-label"><span class="text-danger">*</span> Nationality</label>
<input type="text" id="nationality" name="nationality" class="form-control input-lg" />
</div>
<div class="col-sm-4 padding-minimum">
<label for="mobile" class="control-label"><span class="text-danger">*</span> Gender</label>
<select name="gender" id="gender" class="form-control select2-container step2-select" data-placeholder="Select Gender">
<option></option>
<option value="1">Male</option>
<option value="0">Female</option>
</select>
</div>
答案 1 :(得分:2)
我发现这个dedicated CSS(select2-bootstrap-theme)工作得很好。
bower install select2-bootstrap-theme
<link rel="stylesheet" href="select2.css">
<link rel="stylesheet" href="select2-bootstrap.css">
$( "#dropdown" ).select2({
theme: "bootstrap"
});
select2.full.js
told to be required能够管理尺寸,但我似乎没有“完整”版本就可以使用
答案 2 :(得分:0)
在你的css之前输入-lg +,然后再上课.select2-container example:`
.input-lg+.select2-container--default .select2-selection--single {
height: 46px !important;
padding: 10px 16px;
font-size: 18px;
line-height: 1.33;
border-radius: 6px;
}
.input-lg+.select2-container--default .select2-selection--single .select2-selection__arrow b {
top: 85% !important;
}
.input-lg+.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height: 26px !important;
}
.input-lg+.select2-container--default .select2-selection--single {
border: 1px solid #CCC !important;
box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.075) inset;
transition: border-color 0.15s ease-in-out 0s, box-shadow 0.15s ease-in-out 0s;
}
` 使用@Shehary示例
答案 3 :(得分:0)
只需通过下载select2附加CSS
将select2设置为使用bootstrap主题即可https://github.com/select2/select2-bootstrap-theme
<link href="js/select2-bootstrap-theme/dist/select2-bootstrap.min.css" rel="stylesheet">
然后在JS部分
$('.select2').select2({
theme: "bootstrap"
});
(没有bootstrap-theme)
答案 4 :(得分:0)
虽然select2-bootstrap-theme用于Bootstrap v3,但您可以将其用于Bootstrap v4。
安装
$ npm install @ ttskch / select2-bootstrap4-theme
用法
<link rel="stylesheet" href="/path/to/select2.css">
<link rel="stylesheet" href="/path/to/select2-bootstrap4.css">
$('select').select2({
theme: 'bootstrap4',
});
这是它的Demo