views:

46

answers:

3

How can I change the font color of a disabled SELECT element in IE? No matter what I tried it stays gray. I was able to change the background from gray to white but the text inside the disabled SELECT stays the same. What works perfectly for Firefox has no effect in terms of font color in IE (in this case IE8). You can see the latest situation for both browsers here:

http://www.flickr.com/photos/64416865@N00/4732813702/

I use jQuery to disable the select element:

$(selectObject).attr('disabled', 'disabled');

and here is the CSS class that I use for disabled selects:

select[disabled] {
    color: black;
    background-color: white;
    border-style: solid;
}

I find it very strange that I could easily change the default background color of disabled selects but not the default font color. Any tips or ideas about this? (Or is this completely impossible in IE by using CSS?)

A: 

i never heard of font-color and foreground-color in css before... maybe the IE is confused about that (so do i) and simply goes on strike... (i don't have an IE to test that, please try to remove that lines)

oezi
I removed them, but still the same: select[disabled] { color: black; background-color: yellow; border-style: solid;}
Emre Sevinç
I mean I still get a similar result. IE8 changes the background color to white but does not change the color of the text inside the disabled select into black. It stays gray.
Emre Sevinç
+2  A: 

It might be impossible to do in current IEs. Browsers to come will probably support a :disabled pseudo-class (see http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/html/full/flat/css3-modsel-24.html )

Marijn
According to http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/html/full/flat/css3-modsel-24.html the css Emre is using is supported by IE 7 and above.
Richard
A: 

EDIT: You have to supply support for the most browsers, and only 50% of the browsers supports that type of pseudoclasses, so, if i was you, i would do this:

$(selectObject)
    .attr('disabled', 'disabled')
    .css({
        "color":"black",
        "background-color":"white",
        "border-style":"solid"
    });

hope it works ;)

CuSS
I did it. I have removed the relevant CSS and ran it like your jQuery code above. What is really strange is that, when I look at the page the select's background is still white and the text inside is still gray but I use the Internet Explorer developer tools to see the style details of that select element and when I click on it IE developer tool's CSS pane tells me that: color: black and background-color: white. I'm truly perplexed!
Emre Sevinç
I played with different color names for "color" and "background-color", background color always changes, text's color always remains the same: gray. :(
Emre Sevinç
strange, do you have another js line controling the font and background color?
CuSS
CuSS, no, as far as I can see. Here's the complete code of the function that runs when the SELECT element is manipulated: http://pastebin.com/S5qqLcH7
Emre Sevinç
As you see I also tried to swap the order of .attr and .css, nothing changes for both cases.
Emre Sevinç
A better, hi-lited version: http://pastebin.com/C1xL3aGK
Emre Sevinç
Please email me, to i clean this comment: [email protected]
CuSS