UPDATE
After finally figuring out what OP meant is that the solution originally works fine with one exception, the attribute title
's default behavior is not suppressed, therefore an extra tooltip follows the customized tooltip.
The solution is this: Do not use the title
attribute Without JavaScript you are at the mercy of many default behaviors you cannot control with CSS. But don't get discouraged because there is an alternative that you can use that's not only valid and semantic (if labeled correctly,) it is functionally flexible as well.
Use the data-*
attribute (*
= any string in lower caps no spaces--use dashes instead.)
- We can use any string at any length
- We can name it anything we want (within the previously stated restrictions)
- We can have as many
data-*
attributes on an element and...
- ...that element can be any element.
See the last two examples in Snippet below.
Use the ::before
and ::after
pseudo-elements with the attr()
value. It's not limited to title
which is nice, take a look at the Snippet below.
SNIPPET
div {
margin: 50px;
position: relative;
}
a:link {
text-decoration: none;
color: #000;
border-bottom: 2px solid #f00;
}
a:visited {
text-decoration: none;
color: black;
border-bottom: 2px solid #888;
}
a:hover,
a:active {
text-decoration: none;
color: #f00;
border-bottom: 2px solid #f00;
}
a:hover::after {
content: attr(title);
color: blue;
position: absolute;
top: 3ex;
left: -.5ch;
border-bottom: 0 none transparent;
}
a[name]:hover::after {
content: attr(href);
background: black;
color: cyan;
border-bottom: 0 none transparent;
}
a[target]:hover::after {
content: attr(target);
left: -1.5ch;
background: red;
color: white;
border-bottom: 0 none transparent;
}
a[data-node]:hover::after {
content: attr(data-node);
left: -4ch;
border-bottom: 0 none transparent;
background: black;
color: gold;
}
a[data-anything]:hover::after {
content: attr(data-anything);
left: 0;
border-bottom: 0 none transparent;
color: purple;
width: 8ch;
}
<div>
<a href="#" title="hello">text</a>
</div>
<div>
<a href="#" title="world!">text</a>
</div>
<div>
<a href="h++p://nowhere.lost" name='destination'>Where do I go to?</a>
</div>
<div>
<a href="#" target="#anchorPoint">Target</a>
</div>
<div>
<a href="#" data-node="anyArbitraryString">Data-*</a>
</div>
<div>
<a href="#" data-anything="For anything you want represented by a string">Use Data-*</a>
</div>