data attribute animation

HTML

<div class="box" data-title="YUP YUP DIV DIV DIV">
                I'm a div with a data-title attribute
              </div>

CSS

[data-title] {
  position: relative;
  cursor: pointer;
}
[data-title]::after, [data-title]::before {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
}
[data-title]::after {
  content: attr(data-title);
  bottom: 120%;
  background: rgba(0, 0, 0, 0.7);
  color: #aaa;
  font-size: 0.625em;
  text-align: center;
  white-space: nowrap;
  padding: 10px;
  border-radius: 24px;
  min-height: 24px;
  min-width: 140px;
  max-width: 240px;
  display: grid;
  align-items: center;
  pointer-events: none;
  transition: opacity 0.3s ease-in-out;
  filter: drop-shadow(0 0 1px #aaa) drop-shadow(0 20px 6px rgba(0, 0, 0, 0.5));
  z-index: 10;
}
[data-title]::before {
  content: "";
  bottom: calc(120% - 8px);
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid rgba(0, 0, 0, 0.7);
  transition: opacity 0.2s ease-in-out;
}
[data-title]:hover::after, [data-title]:hover::before {
  opacity: 1;
}
Back to top