[英]Fixed the width of select2
I am using select2
for selecting a candidate skill. 我正在使用
select2
选择候选技能。 I don't want to change my select box width, I want Fixed width for my slelet2 我不想更改选择框的宽度, 我想要slelet2的固定宽度
What have I Tried So far? 到目前为止,我尝试了什么?
//HTML
<select class="skill_select_id" name="skill_select_id">
<?php foreach ( $skills as $skill ) { ?>
<option value="<?= $skill['id'] ?>" ><?= $skill['name'] ?></option>
<?php } ?>
</select>
First I use resolve
首先我用
resolve
//Script
$('.skill_select_id').select2({tags:true, width: 'resolve'});
I have also tried element
, 100%
option in width
我也尝试过
element
, width
100%
选项
//Another Try
$('.skill_select_id').select2({tags:true, width: 'element'});
But it didn't help me to set a Fixed width of select2. 但这并没有帮助我将固定宽度设置为select2。
I don't want to add inline CSS
to solve this problem because if I use the plugin then it must have some solution for this type of problems. 我不想添加
inline CSS
来解决此问题,因为如果使用插件,则它必须针对此类问题提供一些解决方案。
要修复我的下拉宽度,在select2初始化中将其设置为'element'对我来说效果很好:
$("#dropDown").select2({ width: 'element' });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.