tooltip with arrow (no extra element)

by JakobJingleheimer

HTML

<div class="tooltip">Hello World</div>

SCSS

* {
  &,
  &:before,
  &:after {
    box-sizing: border-box;
  }
}

body {
  background: white;
}

.tooltip {
  border: 3px solid #111;
  background-color: #eee;
  padding: 0.2em;
  position: absolute;
  display: inline-block;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  
  &:after {
    border: inherit;
    background-color: inherit;
    bottom: 0;
    content: '';
    display: block;
    height: 1em;
    left: 50%;
    clip-path: polygon(0 0, 45% 55%, 100% 100%, 100% 0%);
    position: absolute;
    transform: translate(-50%, 50%) rotate(135deg);
    width: 1em;
  }
}