I stumbled upon a curiosity.
I have a
select
select
option
option
option
select
width: 100%
You can give display: inline
to your option
and it's size will be based on content length (works fine in Chrome). However this won't work if you have more than 1 option, because it will stack your options horizontally.
select {
width: 20%;
overflow: auto;
}
option {
display: inline;
}
<select size="3">
<option>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option>
</select>
You can use float: left
on option
, it will do the trick (was tested in Chrome):
select {
width: 20%;
overflow: auto;
}
option {
float: left;
}
<select size="3">
<option>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option>
<option>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</option>
</select>