javascripthtmlcssselectjquery-select2

Maximize select width in table when having a label


This looks like one of those things that should have a simple answer, however I could not find any solution for it...

I have a table that contains several select elements, which have some text labels in front, on the same line. I want to maximize the width of the select until the end of the td element. I cannot use fixed widths.

If I use width=100% then the select will push the label out on a different line. By default, the select width is equal to the width of the longest option.

Here is how the default works: http://goo.gl/KiSGcK

Ideally, this should work with select2 also, where the default width is set to the width of the first option.

I have tried wrapping the select and/or the label in divs, setting different css options (float, display inline, etc) with no success. Any ideas?


Solution

  • Finally found a solution: use overflow: hidden.

    Here it is: https://jsfiddle.net/x4FP8/