If you can’t leave the select
without a defined width, I present three solutions:
1.) With jquery, set the title
same as the text of selected
by changing the option:
$('#select1').change(function () {
$(this).attr('title', $(this).children(':selected').text());
});
2.) With CSS, increase width in hover
about the select
:
select {
width:100px;
height:22px;
padding:0;
margin:0;
}
#container {
display:inline-block;
position:relative;
width:100px;
height: 16px;
}
#ancora {
display:inline-block;
position:absolute;
top:0;
left:0;
}
#select2:hover {
width:auto;
}
HTML:
<div id='container'>
<div id='ancora'>
<select id='select2'>
<option>Morango</option>
<option>Menta</option>
<option>Chocolate</option>
<option>Caipirinha</option>
<option>Morango com champanhe</option>
<option>Uva</option>
</select>
</div>
</div>
3.) With jquery, reset the width of the select
according to the width of the selected
by changing the option:
$('#select3').change(function () {
$(this).width($('#tmp-width').html($(this).children(':selected').text()).width() + 30);
});
HTML:
<span id="tmp-width" style="display:none"></span>
See working on Jsfiddle (here is a 4th option)
Make select not fixed in size.
– Oralista de Sistemas
Another suggestion... Put only the
n
first characters of the product name in the dropdown. Or use a more elaborate control like those of Bootstrap, it is worth taking a look.– Oralista de Sistemas