Click to See Complete Forum and Search --> : setting default width in html select element


gondolin7
09-28-2007, 03:30 AM
Hii,

Is there a way to set a default width for a select element in HtML? In order to accomplish this I wrote the following code:

<select style="width: 200px">
<option>one</option>
<option>two</option>
<option>three</option>
</select>

This works but what I want to happen is for it to resize once it already has a longer option width like say: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

gil davis
09-28-2007, 07:32 AM
<select id="s1">
<option>one</option>
<option>two</option>
<option>three</option>
</select>
<script type="text/javascript">
obj = document.getElementById("s1")
if (obj.offsetWidth < 200) {obj.style.width = "200px";}
</script>

gil davis
09-28-2007, 07:34 AM
There is also a "min-width" attribute in CSS, but I think browser support is limited.

Kravvitz
09-29-2007, 10:36 PM
There is also a "min-width" attribute in CSS, but I think browser support is limited.
IE6 doesn't support min-width. IE7 does, but seems not to on <select> elements.

Other browsers; including Firefox, Safari, and Opera 7+; support min-width.