简体   繁体   中英

Chosen with width equal to the largest option

I'm trying to make the DropDownList with the JQuery-Chosen in it reacts like all others "normal" DropDownLists, matching the width equal to the largest option on the DDL. I tried some different approaches to get this done, using css and JQuery, but all I tried became ugly.

At the official page of Chosen, http://harvesthq.github.io/chosen/options.html , it says:

The width of the Chosen select box. By default, Chosen attempts to match the width of the select box you are replacing. If your select is hidden when Chosen is instantiated, you must specify a width or the select will show up with a width of 0.

Any way to workaround this?

Workspace: http://jsfiddle.net/cdtn0ko7/

$('.chosen').chosen({
    width: 'auto'
});

Try this out for size. :D
Fiddle

 $('.chosen').chosen(); 
 .form-control { width: auto; } 

Not sure if I got the question right, but since you are using Bootstrap, you can just do something like this on the css:

.chosen-drop {
  position: inherit !important;
}

I tried using this following code and it worked, check this out:

$('.chosen').chosen({
    width: '100%'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM