Can Select List Options Wrap and Indent Text?
Creating select lists with long option values can pose formatting challenges. Unfortunately, standard HTML
Custom Solution
To achieve wrapping and indentation, one may consider implementing a custom solution. Instead of using native
This approach offers flexibility in text formatting and allows for dynamic adjustments to accommodate varied option lengths.
Example:
<div>
const menu = document.getElementById('my-menu'); // Apply custom formatting to long options menu.querySelectorAll('li').forEach(option => { if (option.offsetWidth > menu.offsetWidth) { option.style.whiteSpace = 'nowrap'; option.style.marginLeft = '1em'; } });
Alternatives
If implementing a custom solution is not viable, an alternative approach involves trimming long option values. However, this may not always provide the desired visual effect.
The above is the detailed content of Can Select List Options Be Wrapped and Indented?. For more information, please follow other related articles on the PHP Chinese website!