Pure CSS Tooltips

by Torwan

HTML

<div class="items">
  <div class="item">
   A tooltip.
    <div class="tooltip"><img src="https://picsum.photos/120/100" /><br />I am a tooltip!</div>
  </div>
  <div class="item">
   A tooltip.
    <div class="tooltip"><img src="https://picsum.photos/100/100" /><br />I am a tooltip!</div>
  </div>
</div>

CSS

.items {
  display: flex;
	flex-direction: column;
	width: 100%;
	justify-content: space-around;
	border: 1px solid #ddd;
	padding: 1em;
	border-radius: 4px;
  margin: 150px 30px;
}

.item {
  text-transform: uppercase;
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  margin: 50px 75px;
  padding: 15px 20px;
  position: relative;
  text-align: center;
  width: 200px;
}

.item .tooltip {
  background: #1496bb;
  bottom: -50%;
  color: #fff;
  display: block;
  left: 50%;
  margin-left: 20px;
  opacity: 0;
  padding: 20px;
  pointer-events: none;
  position: absolute;
  width: 300px;
  transform: translateX(10px);
  transition: all .25s ease-out;
  box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}

/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.item .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.item .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid #1496bb 10px;
  border-bottom: solid transparent 10px;
  border-top: solid transparent 10px;
  top: calc(50% - 10px);
  content: " ";
  height: 0;
  left: 0;
  margin-left: -20px;
  position: absolute;
  width: 0;
}
  
.item:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0px);
}