Options in select Box

S

sandeepsinghal

I have a select (drop down) in my webpage which has got options of
varying length. Some of them very long. I want to fix the width of
select dropw down so that it appears consistent with other elements on
my page (input boxes , other select boxes)
The problem is that since the option length is big, they are not
visible on the screen. This happens only for IE. Firefox nicely expands
the option length and shows the entire option and keeping the select
box width constant at the same time.
Is there any way I can do this in Internet Explorer.

Here is a sample code :

<html>

<head>
<title>Select Box Width</title>
</head>

<body>


<h3>Drop down with onhover</h3>
<select id="id1" name="name1" style="width:60px;">
<option value="1">AAAAAAAAA</option>
<option value="2">BBBBBBBBBBBBBB</option>
<option value="3">CC</option>
<option value="4">DDDDDDDDDDDDDDDD</option>
<option value="5">EEEEE</option>
</select>
<br/>

</body>

</html>
 
J

John

Hi

If you added size=5 then you would display all of them, and the largest
(DDD) would determine the width.
Is that what you are looking for?
<select id="id1" name="name1" style="width:60px;">
<option value="1">AAAAAAAAA</option>
<option value="2">BBBBBBBBBBBBBB</option>
<option value="3">CC</option>
<option value="4">DDDDDDDDDDDDDDDD</option>
<option value="5">EEEEE</option>
</select>


Regards
John
 
J

Jonathan N. Little

John said:
Hi

If you added size=5 then you would display all of them, and the largest
(DDD) would determine the width.
Is that what you are looking for?
<select "size="5" etc>

No, wrong. Size for the SELECT element determines the number of *rows*
displayed and not the number of *characters* as with text inputs...
 
J

John

"> No, wrong. Size for the SELECT element determines the number of *rows*
displayed and not the number of *characters* as with text inputs...

Yes, I agree, but when you display all the rows (5 in this case) the row
with the maximum number of characters will determine the width of the drop
down menu.
Or, alternatively, he could wrap the select in a table <td width="12%">. I
say table knowing that this is deprecated in preference to CSS and div's.
But same idea.

Thanks and regards
John
 
J

Jonathan N. Little

John said:
"> No, wrong. Size for the SELECT element determines the number of *rows*
Yes, I agree, but when you display all the rows (5 in this case) the row
with the maximum number of characters will determine the width of the drop
down menu.

But this does not address what the OP asked. The question was how to
specify the *width* of the SELECT element not the number of *rows*

To the OP the problem is that you cannot specify a different width for
the SELECT and OPTION elements. In IE, the width of the SELECT
constrains the OPTION elements within so

<style type="text/stylesheet">
SELECT { width: 60px; }
OPTION { width: auto; }
</style>

Will 'work' in Firefox, but in IE the OPTION list will not expand but
will also be 60px wide. My advice, adjust you layout so a variable width
SELECT will look acceptable and not try to constrain it.
Or, alternatively, he could wrap the select in a table <td width="12%">. I
say table knowing that this is deprecated in preference to CSS and div's.
But same idea.

Sorry, but what the hell will that do? The TD will not constrain the
OPTION list, just the opposite the TD's default behavior is to expand to
accommodate the contents.
 
S

sandeepsinghal

Jonathan said:
John wrote:
Will 'work' in Firefox, but in IE the OPTION list will not expand but
will also be 60px wide. My advice, adjust you layout so a variable width
SELECT will look acceptable and not try to constrain it.
Take care,

Jonathan

This is what I will have to I guess. Another alternative that I thought
was to try and constrain my data. Thanks for your responses.

Cheers,

Sandeep
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top