Click to See Complete Forum and Search --> : Select Lengths


Javajoob
11-29-2008, 07:31 PM
Hello. I was wondering if you could set select menus to be of a certain length rather than stretching out for the longest option. Thanks on anything you give

NogDog
11-30-2008, 10:07 AM
You can use the size attribute: http://www.w3.org/TR/html4/interact/forms.html#adef-size-SELECT

This may not have the desired effect depending on what you actually want, plus which browser you use, as the specification leaves the actual implementation of select elements pretty much up to the user agent.

javawebdog
11-30-2008, 12:57 PM
If I understand the question what you want to limit is the horizontal width of the display options associated with a particular select element.

Short ans: yes
<style>
option{width:50px;}
</style>
<select style="width:50px">
<option value=''>Opt1</option>
<option value=''>Opt2Opt2</option>
<option value=''>Opt3Opt3Opt3</option>
<option value=''>Opt4Opt4Opt4Opt4</option>
<option value=''>Opt5Opt5Opt5Opt5Opt5</option>
<option value=''>Opt6Opt6Opt6Opt6Opt6Opt6</option>
</select>

BUT it will truncate the displayed values of the longer option elements (bad) and unfortunately 'word-wrap: break-word' is not support by any browser I've seen for 'option'.

NogDog
11-30-2008, 01:39 PM
Ignore my previous reply, I misinterpreted what you were asking. You could use Javawebdog's suggestion to style the select element's width. You probably do not need to set the option elements' width unless you also need it to be limited for some reason.

Javajoob
11-30-2008, 05:29 PM
Ah yes I tried a simular thing and faced the truncation problem. I was pretty sure I had seen handle on one site or another. The maxlength application doesn't seem to be relevant now. There is generally one select I have which looks a bit out of place. It's rather rather long but of course the text in it is left aligned as well.

Don't worry about it Nogdog