tags:

views:

160

answers:

4

Can I get a stylesheet to detect a custom tag on a page element?

I'd like to add some functionality into a stylehseet that can detect a disabled="disabled" attribute on a linkbutton and grey it out.

[UPDATE]

Great suggestions. This effectively resolved the disabled buttons not showing up as grayed out in firefox and google chrome. The following was what I put into the style sheet and now all my link buttons render correctly.

a[disabled]{  
  color:Grey !important;
 text-decoration:none !important;
  }
+1  A: 

I'm pretty sure that you can do the following (here I've assumed that your "linkbutton" element is an "input" element):

input[disabled="disabled"] {
    // Styling
}

Steve

Steve Harrison
+2  A: 

I take it you mean a custom attribute? The CSS rule for this would be (assuming your button is an input element):

input[disabled="disabled"] {
    /* ... */
}

However, this won't work in IE6. Your best bet is probably to add a class to the button (e.g. class="button-disabled"), then style it like so:

input.button-disabled {
    /* ... */
}
harto
A: 

You can do that with css selectors, but it won't work in some browsers. Besides, I wouldn't recomend doing that anyway. Why not just add a disabled class to the linkbutton?

dustyburwell
+1  A: 

You can use CSS2 selector(if browser support it.) to display style base on tag property. But I found some problem when I use "disabled" property in IE8.By default IE8 display tag that is disabled by grey it(stylesheet can't change it).

From the following code, FF3 display green hyperlink. But IE8 display grey hyperlink.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html>
<head>

<title>Ask a Question - Stack Overflow</title>
<style>
a[disabled="true"]
{
    color:Green !important;
}
</style>
</head>

<body>
 <a href="www.microsoft.com" disabled="true">Microsoft Site</a>
</body>
</html>
Soul_Master
+1 for mentioning that this is available in the CSS 2.0 spec.
Cerebrus