css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站

纯 CSS 提示气泡

悬停显示,带箭头,不需要 JS。

结构

HTML
<span class="tip" data-tip="这是提示文字">悬停查看<span class="tip-box">这是提示文字</span></span>

样式

CSS
.tip {
  position: relative;
  font: 600 13px/1 -apple-system, "PingFang SC", sans-serif;
  color: #2b57ff; cursor: default;
  border-bottom: 1px dashed #b9c6ff;
}
.tip-box {
  position: absolute; left: 50%; bottom: 150%;
  transform: translateX(-50%) translateY(4px);
  background: #0d1117; color: #fff;
  font: 500 11px/1.5 -apple-system, sans-serif;
  padding: 6px 10px; border-radius: 6px;
  white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: .18s;
}
.tip-box::after {
  content: ""; position: absolute;
  left: 50%; top: 100%; translate: -50% 0;
  border: 5px solid transparent;
  border-top-color: #0d1117;
}
.tip:hover .tip-box { opacity: 1; transform: translateX(-50%) translateY(0); }

复制后可直接使用;如果要放进已有项目,注意把类名改成你项目里的命名,避免冲突。