views:

719

answers:

2

I have a HTML button. I have tried to render a tooltip on it based on the "title" attribute of the button and it doesn't render. Mainly because it's disabled.

I then tried wrapping the button in a span and setting the "title" attribute of the span.

Hovering over the button that is wrapped in the span still has no effect. The tooltip will render on any other part of the span that is not part of the button tag. Like if i put some text in the span as well as the button, hovering over the text produces the tooltip, but if you hover over the button it will not render.

So: how can I display a tooltip for a disabled button?

A: 

An ideal solution would be cross-browser compatible, and this suggestion isn't; I've tested it only on Ubuntu 9.10, though with Chrome, Firefox, Epiphany and Opera and it seems to work reliably in those, which implies reliability in their Windows counterparts. Obviously IE is an entirely different kettle of fish.

That being said:

This idea's based on the following (x)html:

<form>

<fieldset>

    <button disabled title="this is disabled">disabled button</button>

</fieldset>

</form>

And uses the following CSS to achieve something close to your aim:

    button  {position: relative;
        }

    button:hover:after
        {position: absolute;
        top: 0;
        left: 0;
        content: attr(title);
        background-color: #ffa;
        color: #000;
        line-height: 1.4em;
        border: 1px solid #000;
        }

It's not ideal, but it was the best non-JavaScript idea I could come up with.

David Thomas
Thanks for responding. I hadn't mentioned specifically, but this needs to work in IE7+. Unfortunately it doesn't. In Firefox 3.5 it changes the preformatting of my buttons. Googling around and it seems to be a real problem for many. Thanks for your efforts
giulio
No worries, I'm thinking that JavaScript's probably going to be your best bet, then.
David Thomas
You cook fish in a tea kettle?
Razor Storm
@Razor Storm: a kettle is just a piece of equipment in which water is contained while heated. In this instance '...different kettle of fish' is just an English figure of speech, though it refers to a fish-kettle (http://chefsblade.monster.com/training/articles/97)
David Thomas
Oh ok, makes sense now. I thought he was making a snide remark comparing programming for IE to cooking fish in an unconventional container.
Razor Storm
A: 

Can this be used on input tags too? It doesn't seem to work on disabled text boxes.

Sneha