目录

操作方法 - 工具提示


了解如何使用 CSS 创建工具提示。


将鼠标悬停在下面的文本上:

顶部 工具提示文本
正确的 工具提示文本
底部 工具提示文本
左边 工具提示文本

亲自试一试 »


如何创建工具提示

步骤1)添加HTML:

示例

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>


步骤2)添加CSS:

示例

/* Tooltip container */
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
}

/* Tooltip text */
.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: #555;
  color: #fff;
  text-align: center;
  padding: 5px 0;
  border-radius: 6px;

  /* Position the tooltip text */
  position: absolute;
  z-index: 1;
  bottom: 125%;
  left: 50%;
  margin-left: -60px;

  /* Fade in tooltip */
  opacity: 0;
  transition: opacity 0.3s;
}

/* Tooltip arrow */
.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #555 transparent transparent transparent;
}

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
}
亲自试一试 »

提示:去我们的CSS 工具提示教程了解有关工具提示的更多信息。

提示:要创建 "clickable" 工具提示,请转到我们的如何创建弹出窗口教程

提示:模态框也类似于工具提示。去我们的如何创建模态教程了解情态动词。