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

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

Patricia Arquette
Release: 2024-10-20 15:02:02
Original
1043 people have browsed it

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'); });
});
Copy after login

Apply the following CSS:

select {
  width: 150px; /* or desired width */
}
select.expand {
  width: auto;
}
Copy after login

Assign the class 'wide' to the affected drop-down elements:

<select class="wide">
  ...
</select>
Copy after login

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template