How do I styling disabled SELECT (DropDownList) in

2019-07-06 21:16发布

问题:

I'm writing in ASP.NET (which may be irrelevant in the end). I've already addressed styling the gray on gray default style of disabled/readonly TextBoxes (HTML INPUT), now I'm trying to tackle DropDownLists (HTML SELECT).

I've tried these--which work fine for TextBoxes--but none work for dropdowns:

.ReadableReadonly, select[disabled], input[disabled], select[readonly], input[readonly]
{
    background-color:white;
    color:Black;
}

*[readonly]
{
    background-color:white;
    color:Black;
}

Is there any way to get a disabled dropdown to display in anything but gray text? I'm targeting MSIE 6,7,8 for an intranet only application and I didn't get to pick the browser.

回答1:

Not ie IE6/7, no. These versions use an OS-provided dropdown widget rather than rendering it themselves, so you have very limited styling opportunities. The background-color does work though, so at least the grey-on-white result is easier to read than grey-on-grey.

The reason you may not be getting even the background-color is that attribute selectors like “[disabled]” don't work on IE. Usually you add a rule for ‘.disabled’, and have the script that generates/sets the form fields output “class="disabled"” every time you set disabled.

IE8 is OK.