Select2 not calculating `resolved` width correctly if select is hidden

Hailwood picture Hailwood · Jan 14, 2013 · Viewed 44.8k times · Source

I am using Twitter bootstrap and the fantastic Select2 plugin.

These are working great, I realized you need to set {width: 'resolve'} when initiating Select2 otherwise it looks messed up!.

But I am having an issue with one of my selects, as you can see in the image below, the Referee Type select has an incorrect width.

This is caused due to this field being initially hidden, and only becoming visible if Referee is selected in the Group field.

So, how can I fix this?

Inputs

Answer

Yevgeniy Afanasyev picture Yevgeniy Afanasyev · Jan 14, 2016

Select 2 is smart enough to recalculate it's size if only you set it in the select tag. Like so:

<select style="width: 100%"></select>

CSS formatting on classes would not work!

Read more in "Responsive design - Percent width"