IE Drop-Down List Width Control
Problem:
In Internet Explorer (IE), drop-down lists inherit the width of their parent drop-down box, resulting in an unwieldy appearance when the longest option selector extends beyond the width of the drop-down box.
Solution: CSS- and JavaScript-Based Workaround
To overcome this issue, a combination of CSS and jQuery can be employed to set different widths for the drop-down box and its list of options:
$(document).ready(function() { $('select.wide') .bind('focus mouseover', function() { $(this).addClass('expand').removeClass('clicked'); }) .bind('click', function() { $(this).toggleClass('clicked'); }) .bind('mouseout', function() { if (!$(this).hasClass('clicked')) { $(this).removeClass('expand'); }}) .bind('blur', function() { $(this).removeClass('expand clicked'); }); });
Apply the following CSS:
select { width: 150px; /* or desired width */ } select.expand { width: auto; }
Assign the class 'wide' to the affected drop-down elements:
<select class="wide"> ... </select>
This approach ensures that the drop-down box retains a fixed width while allowing the drop-down list to expand dynamically, accommodating the longest available selector.
The above is the detailed content of How to Adjust Drop-Down List Width in Internet Explorer?. For more information, please follow other related articles on the PHP Chinese website!