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?
Javascript – Drop down list width fit selected item text
asp.net-mvccsshtmljavascript
Related Topic
- Javascript – Get selected value in dropdown list using JavaScript
- Javascript – Get selected text from a drop-down list (select box) using jQuery
- Html – How to create an HTML button that acts like a link
- Css – How to change the cursor into a hand when a user hovers over a list item
- Css – Transitions on the CSS display property
- Css – Font scaling based on width of container
- Html – Hide scroll bar, but while still being able to scroll
Best Answer
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/