Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Tooltips with CSS

Was playing around with the idea of tooltips for social icons on my personal site, but I wanted to use CSS and see if I could “hack” my way into doing this properly.

Here’s what I came up with: http://jsfiddle.net/2PQyx/4/

I’m missing some core CSS from another external stylesheet, but you can get the principle of it... You can see it working on my site: http://joe-hirst.com

What the CSS does:

 .tooltip{
    display: inline;
    position: relative;
}

/* On hover */

.tooltip:hover:after{
    background: #333;
    background: rgba(0,0,0,.8);
    border-radius: 5px;
    top: 10px;
    color: #fff;
    content: attr(title); /* Pulls title to display in background */
    left: 20%;
    padding: 5px 15px;
    position: absolute;
    z-index: 98; /* Sets position directly under my social icons */
    width: 125px;
}

.tooltip:hover:before{
    border: solid;
    border-color: #333 transparent;
    opacity:1.0;  
    border-width: 0px 6px 6px 6px;
    bottom: 5px;
    content: "";
    left: 50%;
    position: absolute;
    z-index: 99;
}

/* Firefox tooltip gap correction */

<!--[if Gecko ]>
.tooltop:hover:after{
    top: 8px;
}

.tooltip:hover:before{
    bottom: 4px; /* Fixes white space issue Firefox */
}
<![endif]-->