[英]How can I show a tooltip when a user hovers over the box shadow of an element?
I have an element that is 1x1 px, with a box shadow that is much larger. 我有一个1x1 px的元素,带有更大的框阴影。 I would like a tooltip to display whenever the user hovers, but the problem is that the tooltip only activates when the user hovers over the 1x1 px area, ignoring the huge box shadow.
我希望每当用户将鼠标悬停时都显示工具提示,但是问题是,仅当用户将鼠标悬停在1x1 px区域上时,工具提示才会激活,而忽略巨大的框阴影。
The blue element (glow) in this fiddle is an example. 这个小提琴中的蓝色元素(发光)就是一个例子。 I tried making the green element (glow2) larger just to show how the tooltip should look.
我尝试将绿色元素(glow2)放大,以显示工具提示的外观。
https://jsfiddle.net/fortunette/fLm3d7oz/1/ https://jsfiddle.net/fortunette/fLm3d7oz/1/
.glow {
width: 1px;
height: 1px;
background-color: blue;
border-radius: 50%;
box-shadow: 0 0 24px 19px blue;
position:absolute;
top:300px;
left:100px;
}
Other requirements are that there are an arbitrary number of these glowing elements at arbitrary positions and sizes. 其他要求是在任意位置和大小上有任意数量的这些发光元素。
Create pseudo-elements that are the same size as the entire area of your divs including the box-shadow. 创建与div的整个区域(包括盒子阴影)大小相同的伪元素 。
The pseudo-element overlays can be transparent . 伪元素叠加层可以是透明的 。 Then use the
:hover
state for the pseudo-elements to trigger the tool tip . 然后将
:hover
状态用于伪元素以触发工具提示 。
Working example: 工作示例:
.glow { width: 1px; height: 1px; background-color: blue; border-radius: 50%; box-shadow: 0 0 24px 19px blue; position: relative; margin: 2em; } .glow:after { content: ""; display: block; height: 50px; width: 50px; position: absolute; top: -25px; /* needs to be half of height and width */ left: -25px; /* needs to be half of height and width */ border-radius: 50%; } .tooltip { position: relative; display: inline-block; border-bottom: 1px dotted black; } .glow .tooltiptext { display: none; width: 120px; background-color: black; color: #fff; text-align: center; border-radius: 6px; padding: 5px 0; /* Position the tooltip */ position: absolute; z-index: 1; } .glow:hover:hover .tooltiptext { display: block; }
<div class="glow"><span class="tooltiptext">Tooltip text</span></div>
The box shadow is not part of the box html element and that is why your tooltip is not showing. 框阴影不是框html元素的一部分,因此未显示工具提示。 I would recommend you wrap your box with in a div and use the tooltip on the outer div that also contains your box shadow.
我建议您将div包装在div中,并在也包含框阴影的外部div上使用工具提示。 Of course you will have to add padding to the outer div so it will fully contain the box shadow.
当然,您将必须向外部div添加填充,以便完全包含框阴影。 This way when the user hover on the box shadow, they are actually hovering on top of the outer div and the tooltip will show up.
这样,当用户将鼠标悬停在框阴影上时,他们实际上是悬停在外部div上方,并且将显示工具提示。 You can use google chrome developing tools (ctrl+shift+i) to see how much padding you will need.
您可以使用Google Chrome开发工具(ctrl + shift + i)来查看需要多少填充。 Use a: hover or JqueryUI tooltip on the outer div class.
在外部div类上使用a:悬停或JqueryUI工具提示。 Hope this helps!
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.