最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chosen with width equal to the largest option - Stack Overflow

programmeradmin1浏览0评论

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, .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: /

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

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/cdtn0ko7/

$('.chosen').chosen({
    width: 'auto'
});
Share Improve this question asked Apr 1, 2015 at 19:37 Luís FernandoLuís Fernando 1332 silver badges12 bronze badges 2
  • I removed {width: 'auto'} and it worked. If that's what you're going for that is. Edit never mind it consumes the entire width of the area. – Wild Beard Commented Apr 1, 2015 at 19:44
  • Small fix, now loading the bootstrap-chosen: jsfiddle/5yL5qy8o – Luís Fernando Commented Apr 1, 2015 at 20:23
Add a ment  | 

3 Answers 3

Reset to default 4

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%'
});
发布评论

评论列表(0)

  1. 暂无评论