Friday, September 19, 2014

How to imitate bootstrap's tooltip without bootstrap

Working with my next project, I had to come up with an idea to imitate tooltip bootstrap style without bootstrap. So, I did some research and found excellent resource. This example gave the idea how create fully-customized tooltip for my project.  Here's an example how I used the sample:


HTML:

<div id="top-menu-bar-buttons">
                  <div class="button1 icon-location-left"><button class="btn-secondary tooltips" type="button">Cancel<span class="width60">Cancel</span></button></div>
                  <div class="button2 icon-location-left"><button class="btn-secondary tooltips" type="button">Preview<span class="width60">Preview</span></button></div>
                  <div class="button3 icon-location-left"><button class="btn-primary tooltips" type="button"><div id="top-menu-bar-button3-text">Review Job</div><i class="fa fa-chevron-right fa-lg"></i><span class="width75">Review Job</span></button></div>
</div>

CSS:

button.tooltips {
  position: relative;
  display: inline;
}
button.tooltips span {
  position: absolute;
  color: #FFFFFF;
  background: #000000;
  height: 19px;
  line-height: 18px;
  text-align: center;
  visibility: hidden;
  border-radius: 6px;
  font-size: 12px;
  font-weight: normal;
}

button.tooltips span:after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  margin-left: -8px;
  width: 0; height: 0;
  border-bottom: 8px solid #000000;
  border-right: 8px solid transparent;
  border-left: 8px solid transparent;
}

button:hover.tooltips span {
  visibility: visible;
  opacity: 0.8;
  top: 40px;
  bottom: 30px;
  left: 100%;
  margin-left: -76px;
  z-index: 999;
}

.width60 {
    width: 60px;
}

.width75 {
    width: 75px;
}

No comments:

Post a Comment