select2 - Setting different width to input and dropdown

后端 未结 8 1904
广开言路
广开言路 2021-02-01 00:47

I am using Select2 3.3.2

I have very very long options in the select. Example:


                        
    
提交评论

  • 2021-02-01 01:20

    I used this and it worked perfect, only that it will affect all the select2

    #select2-drop{
        width: 400px !important;
    }
    
    0 讨论(0)
  • 2021-02-01 01:30

    The property you used is not for controlling the dropdown width. You can use the dropdownCssClass property.

    Here's a demo in jsFiddle.

    JavaScript:

    $(document).ready(function() { 
        $("#e1").select2({dropdownCssClass : 'bigdrop'}); 
    });
    

    CSS:

    .bigdrop {
        width: 600px !important;
    }
    

    Please note that for more recent versions there is now a better solution! See Dave Amphlett's answer

    0 讨论(0)
  • 2021-02-01 01:33
    $("#e1").select2({ width: '100%' });      
    

    Try this. This will set the width of container to 100%

    0 讨论(0)
  • 2021-02-01 01:33

    Try this.

    $(".js-example-basic-single").select2({dropdownAutoWidth : true});

    0 讨论(0)
  • 2021-02-01 01:33

    This worked for me..

     .select2-container--krajee .select2-dropdown--below{
        width:230px !important;
        margin-left: -70px !important;
    }
    
    0 讨论(0)
  • 提交回复
    热议问题