<div class="buttons">
  <button data-tooltip data-tooltip-position="top" aria-description="I'm above! 🌞">
    Hover me!
  </button>  
  <button data-tooltip data-tooltip-position="bottom" aria-description="I'm below 🌚">
    Hover me!
  </button>  
  <button data-tooltip data-tooltip-position="right" aria-description="To the right 👉">
    Hover me!
  </button>  
  <button data-tooltip data-tooltip-position="left" aria-description="To the left 🔚">
    Hover me!
  </button>  
</div>
// Resets
:root {
  font-size: calc(1rem + 1.5vw);
}

body {
  align-items: center;
  background-color: #f2f2f2;
  display: flex;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;  
  justify-content: center;
  margin: 0;
  min-height: 100vh;
  padding: 0;
}

.buttons {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: -0.75rem;
  width: 90%;
}

button {
  background-color: #2866d7;
  border: 0;
  border-radius: 8px;
  box-shadow: 2px 3px 10px rgba(#2866d7, 0.5);
  color: #fff;
  flex-basis: calc((20rem - 100%) * 999);
  flex-grow: 1;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  margin: 0.75rem;
  min-width: calc(25% - 2rem);
  padding: 1em 1.5em;
}

$border-radius: 5px;
$tooltip-background-color: #F18F01;
$tooltip-text-color: #000;
$triangle-size: 8px;
$tooltip-distance: 0.5rem;

/**
 *  {1} The triangle is moved one pixel down two counteract
 *      floating point precision errors in certain browsers.
 *      Without this fix, the parts may seem 0.1px apart.
 */
[data-tooltip][aria-description] {
  position: relative;

  &::before,
  &::after {
    left: 50%;
    opacity: 0;
    position: absolute;
    top: calc(100% + #{$tooltip-distance});
    transition:
      opacity 0.15s ease-in-out,
      visibility 0s 0.15s ease-in-out;
    visibility: hidden;
  }

  &::before {
    border-bottom: $triangle-size solid $tooltip-background-color;
    border-left: $triangle-size solid transparent;
    border-right: $triangle-size solid transparent;
    content: '';
    height: 0;
    transform:
      translateX(-50%)
      translateY(calc(-100% + 1px)); // {1}
    width: 0;
    z-index: 1;
  }

  &::after {
    background-color: $tooltip-background-color;
    border-radius: $border-radius;
    color: $tooltip-text-color;
    content: attr(aria-description);
    font-size: 0.5rem;
    font-weight: 300;
    padding: 0.5em 0.75em;
    transform: translate3d(-50%, 0, 0);
    white-space: nowrap;
    z-index: 1;
  }

  &:hover,
  &:focus {
    &::before,
    &::after {
      opacity: 1;
      transition: opacity 0.15s ease-in-out;
      visibility: visible;
    }
  }

  &[data-tooltip-position="top"] {
    &::before,
    &::after {
      bottom: calc(100% + #{$tooltip-distance});
      top: auto;
    }

    &::before {
      transform:
        translateX(-50%)
        translateY(calc(100% - 1px))
        rotateZ(180deg);
    }
  }

  &[data-tooltip-position="left"] {
    &::before,
    &::after {
      left: 0;
      top: 50%;
    }

    &::before {
      transform:
        translateX(calc(-100% - 1px))
        translateY(-50%)
        rotateZ(90deg);
    }

    &::after {
      transform:
        translateX(calc(-100% - #{$tooltip-distance} + 4px))
        translateY(-50%);
    }
  }

  &[data-tooltip-position="right"] {
    &::before,
    &::after {
      left: auto;
      right: 0;
      top: 50%;
    }

    &::before {
      transform:
        translateX(calc(100% + 5px))
        translateY(-50%)
        rotateZ(270deg);
    }

    &::after {
      transform:
        translateX(calc(100% + #{$tooltip-distance}))
        translateY(-50%);
    }
  }
  @media (hover: none) {
    &::before,
    &::after {
      content: none;
    }
  }
}
View Compiled
// 🎉
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.