Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set height of select2

How to increase the height of the select2 suggestion dropdown?

I tried the idea proposed at https://github.com/select2/select2/issues/144:

.select2-results {
  max-height: 500px;
}

However, that does not work. If I instead set the min-height property, the size is increased, however, I do not want to have a 500px huge dropdown if there are only 1 or 2 items...so min-height is not really an option.

I want the dropdown to dynamically adjust its height to the content, but increase its height up to 500px before a scrollbar is displayed.

like image 942
D.R. Avatar asked Dec 15 '22 02:12

D.R.


2 Answers

Try to use:

.select2-results__options {
   max-height: 500px;
}

If that doesn't work try to add !important so it overwrite it's default max-height (try both methods, yours and mine).

like image 169
Ultrazz008 Avatar answered Dec 28 '22 10:12

Ultrazz008


None of the answers above worked for me, but this did. I'm putting it here for future reference on google :

.select2-container--default .select2-results > .select2-results__options {
    max-height: 400px;
    min-height: 400px;
    overflow-y: auto;
}
like image 26
Alexandre Elshobokshy Avatar answered Dec 28 '22 11:12

Alexandre Elshobokshy