Minimal Tooltip Library with Pure CSS / CSS3 – Tipme

Category: CSS & CSS3 , tooltip | November 6, 2015
Author: huytrq
Views Total: 1,559
Official Page: Go to website
Last Update: November 6, 2015
License: MIT

Preview:

Minimal Tooltip Library with Pure CSS / CSS3 – Tipme

Description:

Tipme provides a simple way to attach tooltips to any DOM elements with CSS classes. Built using CSS, CSS3 and SCSS.

How to use it:

Add the following CSS snippets to your CSS file.

.tipmes {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
}

.tipmes li {
  margin-right: 30px;
  margin-bottom: 30px;
  border: 2px solid #fff;
  text-align: center;
  padding: 1rem;
  flex: 1 1 300px;
}

.tipmes li:nth-child(3n) { margin-right: 0; }

.tipme {
  display: inline-block;
  position: relative;
}

.tipme:before {
  content: '';
  opacity: 0;
  visibility: hidden;
  -webkit-transition: all 0.3s ease-in-out;
  -moz-transition: all 0.3s ease-in-out;
  -ms-transtion: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
}

.tipme:after {
  content: attr(data-tipme);
  position: absolute;
  background-color: #fff;
  color: #000;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 4px;
  opacity: 0;
  visibility: hidden;
  -webkit-transition: all 0.3s ease-in-out;
  -moz-transition: all 0.3s ease-in-out;
  -ms-transtion: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
}

.tipme:hover:before, .tipme:hover:after {
  opacity: 1;
  visibility: visible;
}

.tipme.tipme-tl:after {
  bottom: 115%;
  right: 50%;
}

.tipme.tipme-tc:after {
  bottom: 115%;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
}

.tipme.tipme-tr:after {
  bottom: 115%;
  left: 50%;
}

.tipme.tipme-ml:after {
  top: 50%;
  right: 115%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}

.tipme.tipme-mr:after {
  top: 50%;
  left: 115%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
}

.tipme.tipme-bl:after {
  top: 115%;
  right: 50%;
}

.tipme.tipme-bm:after {
  top: 115%;
  left: 50%;
  -webkit-transform: translateX(-50%);
  transform: translateX(-50%);
}

.tipme.tipme-br:after {
  top: 115%;
  left: 50%;
}

Adding the CSS classes ‘tipme tipme-tl’ to an element will display a ‘top left’ tooltip on mouse hover. Use data-tipme to specify the custom content displayed in the tooltip.

<span class="tipme tipme-tl" data-tipme="This is Tipme!">Top left</span>

More examples.

<span class="tipme tipme-tc" data-tipme="This is Tipme!">Top center</span>
<span class="tipme tipme-tr" data-tipme="This is Tipme!">Top right</span>
<span class="tipme tipme-ml" data-tipme="This is Tipme!">Middle left</span>
<span class="tipme tipme-mr" data-tipme="This is Tipme!">Middle right</span>
<span class="tipme tipme-bl" data-tipme="This is Tipme!">Bottom left</span>
<span class="tipme tipme-bm" data-tipme="This is Tipme!">Bottom center</span>
<span class="tipme tipme-br" data-tipme="This is Tipme!">Bottom right</span>

You Might Be Interested In:


One thought on “Minimal Tooltip Library with Pure CSS / CSS3 – Tipme

  1. whatever

    I hate 97% of all tool tips, but sometimes they are useful.

    After I’ve seen the tooltip once, I almost certainly don’t want to see it again.

    Reply

Leave a Reply