Pure CSS tooltip
October 3rd, 2007
Tag: css webdesign
Today I needed a tooltipsolely based on CSS solely based on CSS, because Javascript-based tooltips would have required enabling javascripting abilities for users. So here is what I did.
First, I created a little css file called tooltip.css with the following content
CSS:
-
/* Usage:
-
<a class="tooltip" href="#">SOME TEXT<span>TOOLTIP TEXT</span></a>
-
*/
-
-
a.tooltip {
-
border-bottom: 1px dashed brown;
-
text-decoration: none;
-
}
-
-
a.tooltip:hover {
-
position: relative;
-
}
-
-
a.tooltip span {
-
display: none;
-
}
-
-
a.tooltip:hover span {
-
display: block;
-
min-width: 10em;
-
max-width: 15em;
-
position: absolute; top: 10px; left: 0;
-
/* formatting only styles */
-
padding: 5px; margin: 10px; z-index: 100;
-
background: #f0f0f0; border: 1px dotted #c0c0c0;
-
opacity: 0.9;
-
/* end formatting */;
-
}
Then I linked this file into the html file where the tooltips should be used
HTML:
-
<style type="text/css">/PATH/TO//tooltip.css</style>
Finally we use it
Example: Lorem ipsum dolor sit amet, consectetur adipisicing elitt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat., sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.







Leave a Reply