@Mukyuu 有用地标记了一个重复的问题,但它已经很老了,2019 年的正确答案可能会大不相同。例如,@Andy Hoffman 提出了一个多年前不可行的解决方法。
This question相似,但不相同。
我们的网页包含多个工具提示。在第一个工具提示出现之前(在 Chrome 上)有明显的 1-2 秒延迟。第一个出现后,当您将鼠标悬停在其他元素上时,随后的工具提示几乎立即出现。
为了清楚起见,工具提示指的是元素的 title
属性中的值,如下所示:
<input type="button" title="Click" value="My Button">
有没有办法让所有工具提示立即出现?
您可以使用元素的伪 content在悬停时显示工具提示。请注意,伪内容不适用于 input
,但 可用于 button
,如下例所示。
.my-button {
position: relative;
}
.my-button:hover::after {
position: absolute;
content: attr(data-tooltip);
bottom: -2.5em;
right: -1em;
background-color: #333;
color: white;
padding: .25em .5em;
}
<input type="button" title="Click" value="My Button">
<button class="my-button" data-tooltip="Click">My Button</button>
更新
作为 input
的解决方法,包含一个包装器 div
,并使用该 div
的数据属性而不是子 输入
。
.input-wrapper {
position: relative;
display: inline-block;
}
.input-wrapper:hover::after {
position: absolute;
content: attr(data-tooltip);
bottom: -2.5em;
right: -1em;
background-color: #333;
color: white;
padding: .25em .5em;
font-size: .8em;
}
<div class="input-wrapper" data-tooltip="Click">
<input type="button" value="My Button">
</div>