Popout with Arrow using HTML and CSS

by Vishwaas Manjunath

HTML

<div class='pop-out up'>
  <span class='arrow'></span>
  Pop Out with Arrow Using HTML and CSS only
</div>

<div class='pop-out down'>
  <span class='arrow'></span>
  Pop Out with Arrow Using HTML and CSS only
</div>

<div class='pop-out left'>
  <span class='arrow'></span>
  Pop Out with Arrow Using HTML and CSS only
</div>

<div class='pop-out right'>
  <span class='arrow'></span>
  Pop Out with Arrow Using HTML and CSS only
</div>

SCSS

.stretch {
  position: absolute;
  border-radius: 5px;
  width: 100%;
  height: 100%;
  left: 0px;
  top: 0px;
}

.pop-out {
  position: relative;
  border-radius: 5px;
  display: inline-block;
  width: 200px;
  height: 100px;
  padding: 5px;
  margin: 25px; 
    
  .arrow {
    display: inline-block;
    position: absolute;
    background-color: white;
    width: 20px;
    height: 20px;
    transform: rotate(-45deg);
    box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.8);
    z-index: -2;
  }
  
  &.up {
    .arrow {
      left: 50%;
      transform: translate(-50%, -75%) rotate(-45deg);
    }
  }
  
  &.down {
    .arrow {
      top: 100%;
      left: 50%;
      transform: translate(-50%, -50%) rotate(-45deg);
    }
  }
  
  &.left {
    .arrow {
      top: 50%;
      transform: translate(-75%, -50%) rotate(-45deg);
    }
  }
  
  &.right {
    .arrow {
      top: 50%;
      left: 100%;
      transform: translate(-50%, -50%) rotate(-45deg);
    }
  }

  &::before {
    content: " ";
    @extend .stretch;
    box-shadow: 0px 0px 2px 0px rgba(0, 0, 0, 0.8);
    z-index: -3;
  }
  &::after {
    content: " ";
    @extend .stretch;
    background-color: white;
    z-index: -1;
  }
}