Out of sheer curiosity, I tried to do something. This is not perfect.
Using em instead of px, problems arise with em, but in this case it is much more reliable than px. How big is Em?
HTML:
<select id="sel" name="sel" style="width:100px;">
<option>Options</option>
<option>IIIIIIIIIIIIIII</option>
<option>MMMMMMMMMMMMMMMMMMMMMMMMM</option>
<option>OptionsOptionsOptionsOptionsOptionsOptions</option>
<option>Options</option>
</select>
JQuery
$('#sel').change(function () {
var len = $('#sel option:selected').val().length;
$('#sel').attr("style", "width:"+len+"em;");
});
Fast JsFiddle
As you will see that it is not perfect, I am much smaller than M, but px are even more dependent on the font. At least they have some consistency. Maybe this will help!
source
share