1 Sept 2015

How to create CSS Tooltips

CSS Tooltips

You can create a lightweight CSS cross browser tooltip easily with a few lines of code.
The HTML:
1This is the <a class="tooltip" href="#">Tooltip Link<span>This will be the text that shows up in the tooltip</span></a> You can place any text you want here.
The CSS:
1a.tooltip {positionrelative}
2a.tooltip span {display:nonepadding:5pxwidth:200px;}
3a:hover {background:#fff;} /*background-color is a must for IE6*/
4a.tooltip:hover span{display:inline;  position:absolute;}
You can add more styles to the above to suit your design. The key is the span is set to display: none until you hover over the link. When you hover over the link the display is changed to show inline and given a position of absolute. position: relative is necessary on the link in order to ensure the tooltip is positioned in relation to the link and not another containing element.
Share:

0 comments:

Post a Comment