Pure CSS Tooltips

What is a tooltip? This is a tooltip an aiding text that appears just when you roll on with the mouse. The basic idea comes from Eric Meyer's pure css popupsa very clever way to get dynamic effects on an html page without using javascript.

My idea was to add position:relative to the link, in order to allow the span element inside to position absolutely respect the parent link. This code has been tested in Ie5.5, Opera7.11 and Mozilla 1.4 and works fine. Solved ie bug adding some z-index, but with the modifications done this technique will be buggy in Opera7.2 .

Now, let's have a look at the basic csscascade style sheets, the separation from content and presentation code for the tooltip:

a.info{
    position:relative; /*this is the key*/
    z-index:24; background-color:#ccc;
    color:#000;
    text-decoration:none}

a.info:hover{z-index:25; background-color:#ff0}

a.info span{display: none}

a.info:hover span{ /*the span will display just on :hover state*/
    display:block;
    position:absolute;
    top:2em; left:2em; width:15em;
    border:1px solid #0cf;
    background-color:#cff; color:#000;
    text-align: center}

Implemenation


<a class=info href="#">This is a tooltip <span>an 
aiding text that appears just when you roll on with the mouse</span></a>


css tooltips


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site