Is there a way in javascript/jquery or css to make html <select>/@Html.DropDownList auto width so it fits currently selected item, I tried with diplay:inline-block and width:auto but width always seems to fit largest item on list?
Is there a way in javascript/jquery or css to make html <select>/@Html.DropDownList auto width
Share
My answer is similar to D3mon-1stVFW’s, but instead uses a hidden drop-down to set the width on dynamically. As long as you use the same styling for your hidden and “real” one, it should account for different font sizes, decoration, etc. Here’s the HTML:
And the Javascript:
JSFiddle here: http://jsfiddle.net/kn9DF/1/