简体   繁体   English

防止在工具提示容器上悬停效果

[英]prevent hover effect on a tooltip container

I created a tooltip file 我创建了一个工具提示文件

 [tooltip]:before { content: attr(tooltip); position: absolute; opacity: 0; right: 0; top: 110%; z-index: 9999; color: #ffffff; background: #333333; padding: 10px; transition: all 0.5s ease; } [tooltip]:hover:before { opacity: 1; } [tooltip] { position: relative; } /* other stuff */ #container { width: 150px; height: 50px; background: red; } 
 <div id="container" tooltip="Tooltip">Div with tooltip</div> 

It works really fine but when hovering over the tooltips position, the hover effect triggers too. 它确实可以正常工作,但是当将鼠标悬停在工具提示位置时,也会触发悬停效果。 The hover effect should just get triggered when hovering over the element the tooltip is attached to. 将鼠标悬停在工具提示所附加的元素上时,应该刚刚触发悬停效果。

How can I make the tooltip only appear when hovering the element? 如何使工具提示仅在将元素悬停时显示?

You can remove the pointer-events from the tooltip: 您可以从工具提示中删除pointer-events

 [tooltip]:before { content: attr(tooltip); position: absolute; opacity: 0; right: 0; top: 110%; z-index: 9999; color: #ffffff; background: #333333; padding: 10px; transition: all 0.5s ease; pointer-events: none; /* add this */ } [tooltip]:hover:before { opacity: 1; } [tooltip] { position: relative; } /* other stuff */ #container { width: 150px; height: 50px; background: red; } 
 <div id="container" tooltip="Tooltip">Div with tooltip</div> 

Add pointer-events: none; 添加pointer-events: none; to tooltip class. 工具提示类。

It disables mouse events (clicking, dragging, hovering, etc.) on elements. 它禁用元素上的鼠标事件(单击,拖动,悬停等)。

Hope this helps :) 希望这可以帮助 :)

 [tooltip]:before { content: attr(tooltip); position: absolute; opacity: 0; right: 0; top: 110%; z-index: 9999; color: #ffffff; background: #333333; padding: 10px; transition: all 0.5s ease; pointer-events:none; } [tooltip]:hover:before { opacity: 1; } [tooltip] { position: relative; } /* other stuff */ #container { width: 150px; height: 50px; background: red; } 
 <div id="container" tooltip="Tooltip">Div with tooltip</div> 

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

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