简体   繁体   English

将鼠标悬停在元素上时指定工具提示的位置

[英]Specify the location of the tooltip when hovering over an element

When I mouse over div.divClass , the tooltip text should show. 当我将鼠标悬停在div.divClass ,应显示工具提示文本。

How can I achieve that? 我怎样才能做到这一点?

 .divClass { width: 200px; height: 200px; border: 1px solid } 
 <div class="divClass"> <a href="#" title="Tooltip text"> test </a> </div> 


EDIT 编辑

Actually I want to show tooltip top of the ANCHOR element when mouse over on div. 实际上我想在鼠标悬停在div上时显示ANCHOR元素的工具提示顶部。 If I add title in Div means I'm getting alignment issue. 如果我在Div中添加标题意味着我会遇到对齐问题。

The title attribute cannot force a tooltip to appear in one fixed location, regardless of where the hover occurs. 无论悬停发生在何处, title属性都不能强制工具提示出现在一个固定位置。 That's not normally how the tooltip works. 这通常不是工具提示的工作原理。 However, here's a method that may work for you. 但是,这是一种可能适合您的方法。

 .divClass { width: 200px; height: 200px; border: 1px solid; position: relative; margin: 30px; cursor: pointer; } span { display: none; } .divClass:hover > span { display: inline-block; position: absolute; top: -25px; left: 0; border: 2px solid red; background-color: yellow; } 
 <div class="divClass"> <a href="#" title="Tooltip text"> test </a> <span>Tooltip text</span> </div> 

jsFiddle 的jsfiddle

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM