Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the appearance of a disabled link

Tags:

html

css

Is it possible to change the appearance of an html link when it's disabled? For example using something like:

a.disabled
{
  color:#050;
}

<a class="disabled" disabled="disabled" href="#">Testing</a>

The example above does not seem to work with IE but works for Firefox, on IE it remains gray even when I set the colour in the style. If I remove the disabled="disabled" however it works.

like image 234
Mercurious Avatar asked Jul 21 '09 16:07

Mercurious


People also ask

How do I GREY out a link?

Disable a link # It is still possible to disable a link by following 3 steps: remove the href attribute so that it can no longer receive the focus. add a role="link" so that it is always considered a link by screen readers. add an attribute aria-disabled="true" so that it is indicated as being disabled.

How do I change the look of a link in HTML?

To change the color of links in HTML, use the CSS property color. Use it with the style attribute. The style attribute specifies an inline style for an element. Use the style attribute with the CSS property color to change the link color.

How do I change the color of an active link?

Use the :active class to change the color of active links. Possible values could be any color name in any valid format.


2 Answers

The :disabled pseduo class only works with input fields, like text, radio, checkbox, etc. and applies when you give the element the attribute `disabled="disabled". IE6, however, doesn't recognize the pseudo class, so you'll need to use a class separately to make it work.

<input type="text" value="You can't type here" disabled="disabled" class="disabled" />

can be styled with

input[disabled="disabled"], input.disabled {
    /* whatever you want */
}

The pseudo class will apply to modern browsers while the class will cover IE6.

Like Radeksonic said, if you want the disabled CSS to appear on other elements, like anchors, you'll just need to make and use a class. There's no disabled attribute for <a>s

like image 76
Andrew Avatar answered Oct 13 '22 05:10

Andrew


For a link like the one you provided in the comment:

<a href="#" disabled="disabled">some link</a>

The style would be (just like any other selector based on an attribute):

a[disabled=disabled] {
  color: red;
  font-weight: bold;
}

If I was in your place, I'd check for cross-browser behavior, though. I haven't seen the disabled attribute used before.

like image 34
Sinan Taifour Avatar answered Oct 13 '22 05:10

Sinan Taifour