Tooltips with CSS

Pure CSS tooltips by SantaKlauss shows you how to display tooltips using purely CSS. The idea is not unlike Nice Titles, though the execution is very different - Nice Titles uses the DOM to extract the nicetitles, the tooltips use only CSS.

The smart part is when printing: the tooltips are “inlined” and bracketed appropriately so that they show up in the normal flow of the document when printing.

Still, I consider the execution to be semantically incorrect since the tooltip requires the anchor tag <a> to work - the text that is “tooltipped” is not an anchor. A better way would have been to use a standard <span> tag. Of course, this then breaks in IE because IE only supports the :hover pseudo-class on the <a> tag. Thanks to whatever:hover, however, this can easily be fixed. Also, there seems to be no need for the z-index fix as mentioned (tested on IE/Win 5, 5.5 and 6). The CSS is below:

body {
behavior:url(/htc/csshover.htc);
}
span.info{
position:relative;
background-color:#ecc;
color:#000;
text-decoration:none
}
span.info:hover { background-color:#e96 }
span.info span.tooltip { display: none }
span.info:hover span.tooltip {
display:block;
position:absolute;
top:2em; left:2em; width:15em;
border:1px solid #0cf;
background-color:#cff;
color:#000;
text-align: center
}

Here’s an example.

10 Comments & TrackBacks ()

Paper doll icon
Full(o)bloG's Gravatar

tooltip con CSS
giusto qualche giorno fa chiedevo a futa se avesse qualche idea di come associare ad un tooltip un particolare CSS, ed ecco che su redemption oggi pubblicano la soluzione ai miei problemi!

ciuaz

Posted by: Full(o)bloG on January 22, 2004 7pm

Paper doll icon
Computer Toaster's Gravatar

Nicer CSS tooltips
Mark Newhouse’s CSS Help was one of the first CSS tricks I learned. Cheah Chu Yeow takes the idea up a level: The smart part is when printing: the tooltips are “inlined” and bracketed appropriately so that they show up in the normal f…

Posted by: Computer Toaster on January 22, 2004 8pm

Paper doll icon
teser's Gravatar

Merci, c’est vraiment super comme truc !
À force de bidouiller IE avec plein de htc, on va finir par le rendre compatible ;-)

Posted by: teser on February 1, 2004 6am

Paper doll icon
hebig.org/blog's Gravatar

Quick Links, February 01
CSS Not to miss: 10 lines of JavaScript to emulate the :hover pseudo-class in IE5+ And it works: Vertical…

Posted by: hebig.org/blog on February 1, 2004 9am

Paper doll icon
FreeTacoHere's Gravatar

web design: accessibility
Well, yesterday I fianlly uploaded my first version (2.0) of AustinSlam.com .

Posted by: FreeTacoHere on February 21, 2004 5am

Paper doll icon
Brian A. Wilt's Gravatar

Hey–there’s actually a bug in the script that can be viewed here:
Overlapping Tooltips
The solution is to make the z-index of the containing span 5 normally, and then boost it to 10 when you hover on it.
Otherwise, thank you very much!

Posted by: Brian A. Wilt on March 18, 2004 4am

Paper doll icon
!'s Gravatar

er, how do you customize the tooltip rectangle so that it has rounded edges like yours? ^^;

Posted by: ! on April 16, 2004 5pm

Paper doll icon
Cheah Chu Yeow's Gravatar

You would want to take a look at NiceTitles.

The rounded edges currently only work on Gecko browsers like Mozilla and Firefox, until CSS border-radius is implemented.

Posted by: Cheah Chu Yeow on April 16, 2004 6pm

Paper doll icon
Matt's Gravatar

So will the tooltip run off the page if the link is at the far right or bottom of the page?

Posted by: Matt on April 27, 2006 6am

Paper doll icon
Alys's Gravatar

What is the “/htc/csshover.htc);” thing about, is there a file named csshover.htc that you need to write/upload?

Posted by: Alys on August 1, 2006 8pm

You can subscribe to the RSS feed for comments on this post.

Sorry, this entry is no longer accepting comments. If you have something you really want to say, you can write me.