I need to change the style for a disabled input element in CSS.
You can use readonly
instead. Following would do the trick for you.
<input type="text" class="details-dialog" style="background-color: #bbbbbb" readonly>
But you need to note the following. Depends on your business requirement, you can use it.
A readonly element is just not editable, but gets sent when the according form submits. A disabled element isn't editable and isn't sent on submit.
You can:
input[type="text"][disabled] {
color: red;
}
Replace disabled
with readonly="readonly"
. I think it is the same function.
<input type="text" class="details-dialog" readonly="readonly" style="color: ur color;">
It seems nobody found a solution for this. I don't have one based on only css neither but by using this JavaScript trick I usually can handle disabled input fields.
Remember that disabled fields always follow the style that they got before becoming disabled. So the trick would be 1- Enabling them 2-Change the class 3- Disable them again. Since this happens very fast user cannot understand what happened.
A simple JavaScript code would be something like:
function changeDisabledClass (id, disabledClass){
var myInput=document.getElementById(id);
myInput.disabled=false; //First make sure it is not disabled
myInput.className=disabledClass; //change the class
myInput.disabled=true; //Re-disable it
}
You can't for Internet Explorer.
See this comment I wrote on a related topic:
There doesn't seem to be a good way, see: How to change color of disabled html controls in IE8 using css - you can set the input to
readonly
instead, but that has other consequences (such as withreadonly
, theinput
will be sent to the server on submit, but withdisabled
, it won't be): http://jsfiddle.net/wCFBw/40
Also, see: Changing font colour in Textboxes in IE which are disabled
input[disabled], input[disabled]:hover { background-color:#444; }