简体   繁体   English

当用户将鼠标悬停在元素的框阴影上方时,如何显示工具提示?

[英]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.

相关问题 当工具提示悬停在 d3 地图中的文本上时,如何继续显示工具提示 - How can I continue displaying a tooltip when it hovers over text in a d3 map 用户将鼠标悬停在某些文本上时如何打开小窗口? - How can I open a small window when the user hovers over some text? 当用户将鼠标悬停在某个地址上时,如何显示弹出式Google Map? - How can I have a popup Google Map appear when the user hovers over an address? 当鼠标悬停在图像中时如何显示图像? - How can I show the image when the mouse hovers in an image? 仅当鼠标悬停在颜色上时,如何显示按钮? - How can I show the button only when the mouse hovers on the color? p5.j​​s:当我的鼠标悬停在处理中的草图中不同的文本元素上时,如何使文本出现? - p5.js: How can I make text appear when my mouse hovers over a different text element in the sketch in processing? p5.j​​s:当我的鼠标悬停在处理草图中的不同元素上时,如何使文本出现? - p5.js: How can I make text appear when my mouse hovers over a different element in the sketch in processing? 当用户将鼠标悬停在HTML文档中的静态图片上时如何显示Google地图 - How to show google map when user hovers over static image in html document 当用户将鼠标悬停在每个“键盘”按钮上时,我可以使用随机颜色吗? - Can I have random colors when the user hovers over each “keyboard” button? 当访问者悬停在元素上时,如何显示解释文本框? - How to make an explanation text box display when a visitor hovers on an element?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM