tags:

views:

61

answers:

5

I have looked all over and can't figure this out: how do you target the disabled state submit button in css?

For example: How would I target and style this button:

<input value="Validate" disabled="disabled" type="submit"/>
+3  A: 
input[disabled='disabled'][type='submit']
{
...
}

doesn't work in IE 6 but should in all other browsers. Reference

There is also the :disabled pseudo-class but that's not supported in IE at all.

Styling disabled elements is difficult, as they sometimes have properties that can't be overridden. This article shows what stylings apply in which browsers: Styling disabled form controls with CSS

Pekka
Wait, won't this style all disabled elements? Is there a way to specifically target disabled buttons?_
Thomas
@Thomas yup, it will. It should be possible to combine this with `[type='submit']` but I don't know how to be honest. A class would work like this: `input.classname[disabled....`
Pekka
@Thomas try `[type='submit'][disabled='disabled']` no guarantees though
Pekka
+1  A: 

There is no pseudo class defined in CSS for a disabled state.

My guess is to use JQuery to change the CSS class for the disabled buttons.

Code for JQuery:

<script language="javascript">
    $('input[type=button]').each(function () {
        if ($(this).attr('disabled') == true)
        {
            $(this).addClass('disabled');
        }
    });
</script>

Add a style element 'disabled'.

rdkleine
There is a pseudo-class in CSS3, but it's not supported by IE.
Pekka
+1, as browser support is very patchy, going down a JS route seems a good solution, as long as you know for sure the clientside has javascript enabled.
danp
Im using Jquery, how would I implement this?
Thomas
A: 

One way I can think of for this is by setting the class of the button to disabled and then using "input.disabled" to specify the appropriate CSS. Would that work in the context you are doing this?

AJ
I thought about that, but I am concerned that this might be seen as poor coding by the engineer... I never know what is going to hack those guys off.
Thomas
I agree it's not...'nice', but it's quite a simple solution. Never having worked in a professional coding environment, I don't know what they'll expect, though!
AJ
A: 

CSS3 adds the :disabled pseudoclass, which exactly does what you want.

input:disabled {
 /*Disabled styles for input elements here*/
}

As this page shows all major browsers (except IE8) support this tag, so it seems unusable yet (unless you do not need IE support)

Veger
If you have a boss or client that doesn't require IE support, please call me! ;-) I needed weeks and reams of stats just to be allowed to drop IE6 and IE7.
Brock Adams
Hehe... Well you *did* manage to drop IE6 and IE7, saves lots of trouble already!
Veger
+1  A: 

You can use:

    input[disabled=disabled][type=submit] {
        background:green;
    }

Works on Firefox and is reportedly good on all but IE6. But I haven't personally tested this kind of combo selector.

PS: A more robust, cross-browser method, using jQuery...

$("input[disabled=disabled][type=submit]").css
({
    'background':   'yellow',
    'color':        'blue'
});
Brock Adams
Wow that worked. +1000 Thanks!
Thomas
You're welcome!
Brock Adams