Home  >  Article  >  Web Front-end  >  How to Adjust Drop-Down List Width in Internet Explorer?

How to Adjust Drop-Down List Width in Internet Explorer?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-20 15:02:02961browse

How to Adjust Drop-Down List Width in Internet Explorer?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn