简体   繁体   English

选择宽度等于最大选项

[英]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. 我正在尝试使带有JQuery-Chosen的DropDownList像所有其他“正常” DropDownLists一样做出反应,匹配宽度等于DDL上的最大选项。 I tried some different approaches to get this done, using css and JQuery, but all I tried became ugly. 我使用CSS和JQuery尝试了一些不同的方法来完成此操作,但是我尝试的所有方法都变得难看。

At the official page of Chosen, http://harvesthq.github.io/chosen/options.html , it says: 在Chosen的官方页面http://harvesthq.github.io/chosen/options.html上 ,它显示:

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. 如果实例化“选择”时隐藏了选择,则必须指定宽度,否则选择将显示为0。

Any way to workaround this? 有什么解决方法吗?

Workspace: http://jsfiddle.net/cdtn0ko7/ 工作区: http : //jsfiddle.net/cdtn0ko7/

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

Try this out for size. 试试这个尺寸。 :D :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: 不知道我的问题是否正确,但是由于您正在使用Bootstrap,因此可以在CSS上执行以下操作:

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

I tried using this following code and it worked, check this out: 我尝试使用下面的代码,它起作用了,请检查一下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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