简体   繁体   English

悬停在子元素上时未触发 Bootstrap 5 工具提示

[英]Bootstrap 5 Tooltip not triggered when hovering over child element

I'm using Bootstrap 5 and I'm trying to trigger a tooltip when I hover over an anchor tag which contains a Fontawesome Icon.我正在使用 Bootstrap 5,当我 hover 在包含 Fontawesome 图标的锚标签上时,我试图触发工具提示。 However, when I hover over the part of the tag where the icon sits, the tooltip hides.但是,当我在图标所在的标签部分上 hover 时,工具提示会隐藏。

I have the following anchor tag:我有以下锚标签:

<a href="https://twitter.com/mytwitterhandle" target="_blank" data-toggle="tooltip" data-placement="top" title="" data-original-title="Tooltip on top">
    Hovering over text will trigger the tooltip but it is removed when hovering over the icon... 
    <i class="fab fa-fw fa-twitter" aria-label="Visit Twitter Page" data-original-title="" title=""></i>
</a>

Here's the javascript to trigger it (taken from the official docs):这是触发它的 javascript(取自官方文档):

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-toggle="tooltip"]'));

var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
    return new bootstrap.Tooltip(tooltipTriggerEl);
});

Any ideas?有任何想法吗?

EDIT!编辑!

OK, so I got around this by inserting the Fontawesome icon as a pseudo element.好的,所以我通过插入 Fontawesome 图标作为伪元素来解决这个问题。 Would still be interested to hear if anyone has a solution though.不过,如果有人有解决方案,仍然会很感兴趣。

Your issue looks like https://github.com/twbs/bootstrap/issues/31324 and has been fixed in Bootstrap 5 alpha 2 by https://github.com/twbs/bootstrap/pull/30928 .您的问题看起来像https://github.com/twbs/bootstrap/issues/31324并已由 https://github.com/twbs/bootstrap/pull/30928 在 Bootstrap 5 alpha 2 中修复

A workaround for Bootstrap 5 alpha 1 is https://github.com/twbs/bootstrap/issues/31080#issuecomment-645544440 : Bootstrap 5 alpha 1 的解决方法是https://github.com/twbs/bootstrap/issues/31080#issuecomment-645544440

.fas {
  z-index: -1;
}

You use this code:您使用以下代码:

<a href="https://twitter.com/mytwitterhandle"
  target="_blank"
  data-toggle="tooltip"
  data-placement="top"
  title=""
  data-original-title="Tooltip on top">

But need to use this:但是需要使用这个:

<a href="https://twitter.com/mytwitterhandle"
  target="_blank"
  data-bs-toggle="tooltip"
  data-bs-placement="top"
  title=""
  data-original-title="Tooltip on top">

Difference is data-toggle vs. data-bs-toggle and data-placement vs. data-bs-placement .区别在于data-toggledata-bs-toggledata-placementdata-bs-placement

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

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