开发者

Styling disabled <select> (dropdown boxes) in HTML

开发者 https://www.devze.com 2023-01-18 17:45 出处:网络
One of our customers has a hard time reading the grey text in disabled controls in our web-based application:

One of our customers has a hard time reading the grey text in disabled controls in our web-based application:

Styling disabled <select> (dropdown boxes) in HTML

We would like to change the style to a light grey background and a black text. Unfortunately, most browsers (including IE, which is what the开发者_如何学Python customer is using) ignore the color: ... CSS attribute on disabled controls, so we cannot change the foreground color.

For text boxes (input type="text"), this can easily be workarounded by using the readonly instead of the disabled attribute. Unfortunately, this is not an option for dropdowns (select) or checkboxes (input type="checkbox").

Is there an easy workaround for that? Preferebly one where the control does not need to be replaced by another type of control? (...since our controls are rendered by ASP.NET)

PS: Using the [disabled] selector in CSS does not make a difference.


In Internet Explorer 9, support will be added for the :disabled pseudo-selector (ref). I don't know whether that will honor the "color" property, but it seems likely.

In older versions of IE, you can adjust the background color (but not the color). Thus:

    <style type="text/css">
        select[disabled] { background-color: blue; }
    </style>

That works in IE 7 and IE 8. You still can't alter the foreground color, but you can change the background color to contrast more strongly with the gray that IE assigns it when it's disabled.


This worked for me in webkit and Firefox

select:disabled{
   opacity: 0.6;
}


For those still finding this.

Not working:

select[disabled] { background-color: blue; }

Working:

select option [disabled] { background-color: blue; } will do


This worked for me

select[disabled='disabled']::-ms-value {
    color: red;
   }


Sorry for my english...

That's not possible using css just, IE doesn't allow change properties of a disabled select tag


You can try the following:

    <style>
        /*css style for IE*/
        select[disabled='disabled']::-ms-value {
            color: #555;
        }
        /*Specific to chrome and firefox*/
        select[disabled='disabled'] {
            color: #555;
        }
    </style>


I know this is question is old but this code worked well for me.
It allowed for full control of text and background color. I used this code with a disabled select control whose value is set based on a value from another select. I didn't want to see the grayed background, especially when the value had not yet been set.

CSS

<style>
.whatever-control:disabled, .whatever-control[readonly] {
    background-color: white;
    opacity: 1;
    color: blue;
    font-weight: bold;
}
</style>

Form

<select id = "SelectState" name="SelectState" class="whatever-control" disabled="disabled">
    <option value="AK">Alaska</option>
    <option value="AL">Alabama</option>
    <option value="AR">Arkansas</option>
    <option value="AZ">Arizona</option>
    <option value="CA">California</option>
    <option value="CO">Colorado</option>
    <option value="CT">Connecticut</option>
    <option value="DC">District of Columbia</option>
    <option value="DE">Delaware</option>
    <option value="FL" selected="selected">Florida</option>
    <option value="GA">Georgia</option>
</select>


You can try,

option:disabled{
   opacity: 0.6;background-color: #ff888f;
}
<select id="HouseCleaningEmp" onChange="myCalculater()">
  <option value="1">option 1 </option>
  <option value="2">option 2 </option>
  <option value="3">option 3 </option>
  <option value="4">option 4 </option>
  <option value="5" disabled>option 5 </option>
  <option value="6" disabled>option 6 </option>
  <option value="7">option 7 </option>
  <option value="8">option 8 </option>
</select>

0

精彩评论

暂无评论...
验证码 换一张
取 消