Css -100%的人做到了。那是半个小时绝望地寻找答案“解决”。谢谢:)这是目前为止最好的答案。但现在,对我来说,搜索字段并没有填满所有的宽度。有没有简单的方法来纠正这个问题?效果很好。。。除非您正在使用占位符,否则,如果您的选项小于占位符,占位符文本将被截断:

Css -100%的人做到了。那是半个小时绝望地寻找答案“解决”。谢谢:)这是目前为止最好的答案。但现在,对我来说,搜索字段并没有填满所有的宽度。有没有简单的方法来纠正这个问题?效果很好。。。除非您正在使用占位符,否则,如果您的选项小于占位符,占位符文本将被截断:,css,twitter-bootstrap,angularjs,jquery-select2,Css,Twitter Bootstrap,Angularjs,Jquery Select2,-100%的人做到了。那是半个小时绝望地寻找答案“解决”。谢谢:)这是目前为止最好的答案。但现在,对我来说,搜索字段并没有填满所有的宽度。有没有简单的方法来纠正这个问题?效果很好。。。除非您正在使用占位符,否则,如果您的选项小于占位符,占位符文本将被截断:( $(document).ready(function() { $("#myselect").select2({ width: 'resolve' }); }); $("#myselect").select2


-100%的人做到了。那是半个小时绝望地寻找答案“解决”。谢谢:)这是目前为止最好的答案。但现在,对我来说,搜索字段并没有填满所有的宽度。有没有简单的方法来纠正这个问题?效果很好。。。除非您正在使用占位符,否则,如果您的选项小于占位符,占位符文本将被截断:(
$(document).ready(function() { 
    $("#myselect").select2({ width: 'resolve' });           
});
$("#myselect").select2({ width: '100%' });      
$("#your_select_id").select2({
      containerCss : {"display":"block"}
});
<select class="smartsearch" name="search" id="search" style="width:100%;"></select>
$("select").select2({
  dropdownAutoWidth: true
});
$("#offialNumberArea").show();
$("#eventNameArea").hide();

$('.selectCriteria').change(function(){
    var thisVal = $(this).val();
    if(thisVal == 'sailor'){
        $("#offialNumberArea").show();
        $("#eventNameArea").hide();
    }
    else
    {
        $("#offialNumberArea").hide();
        $("#eventNameArea").show();
        $("#MISSION_ID").select2();
    }
});
//HTML
<select id="" class="input-xlg">
</select>
<input type="text" id="" name="" value="" class="input-lg" />

//CSS
.input-xxsm {
  width: 40px!important; //for 2 digits 
}

.input-xsm {
  width: 60px!important; //for 4 digits 
}

.input-sm {
  width: 100px!important; //for short options   
}

.input-md {
  width: 160px!important; //for medium long options 
}

.input-lg {
  width: 220px!important; //for long options    
}

.input-xlg {
  width: 300px!important; //for very long options   
}

.input-xxlg {
  width: 100%!important; //100% of parent   
}
$(document).ready(function() { 
        $("#myselect").select2({ width: 'resolve' });           
});
.select2-container {
width: 100% !important;
}
 // * Select2 4.0.7

$('.select2-multiple').select2({
    // theme: 'bootstrap4', //Doesn't work
    // width:'100%', //Doesn't work
    width: 'resolve'
});

//The Fix
$('.select2-w-100').parent().find('span')
    .removeClass('select2-container')
    .css("width", "100%")
    .css("flex-grow", "1")
    .css("box-sizing", "border-box")
    .css("display", "inline-block")
    .css("margin", "0")
    .css("position", "relative")
    .css("vertical-align", "middle")
    $('#searchFilter').select2({
        width: 'resolve',
    });
.select2-container {
    min-width: 100% !important;
}
<select class="form-control" style="width: 160px;" id="searchFilter" name="searchfilter[]">
<select id="myselect" style="width: 20%;">
    <option>...</option>
</select>
$(document).ready(function() { 
    $("#myselect").select2({ width: 'style' }); //This will use style attr of the select element  
});