如何将工具提示添加到Bootstrap 5浮动标签表单?

huangapple go评论64阅读模式
英文:

How to Add Tooltips to Bootstrap 5 Floating Labels Form?

问题

可以在 Bootstrap 5 浮动标签文本上添加工具提示或弹出框吗?

我有一个使用浮动表单字段的表单,我想使用工具提示或弹出框功能向特定的表单字段添加说明。我可以在标准表单实现(非浮动)上使其工作,但在使用浮动标签时却不行。

这是否可以实现?如何实现?

<div class="form-floating">
   <input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
   <label for="floatingInput">
      电子邮件地址 <button href="#" class="btn badge text-bg-primary" type="button" data-bs-toggle="tooltip" title="提示标题!">工具提示</button>
   </label>
</div>
英文:

Is it possible to add tooltips or popovers to Bootstrap 5 floating labels text?

I have a form that uses floating form fields and I want to add instructions to certain form fields using the tooltip or popovers functionality. I can get it to work on the standard form implementation (non-floating), but not when I use floating labels.

Can this be done? How?

&lt;div class=&quot;form-floating&quot;&gt;
   &lt;input type=&quot;email&quot; class=&quot;form-control&quot; id=&quot;floatingInput&quot; placeholder=&quot;name@example.com&quot;&gt;
   &lt;label for=&quot;floatingInput&quot;&gt;
      Email address &lt;button href=&quot;#&quot; class=&quot;btn badge text-bg-primary&quot; type=&quot;button&quot; data-bs-toggle=&quot;tooltip&quot; title=&quot;Tooltip Title!&quot;&gt;Tooltip&lt;/button&gt;
   &lt;/label&gt;
&lt;/div&gt;

答案1

得分: 1

pe-auto类添加到<label>或具有工具提示的元素上(在本例中是<button>),以允许指针事件。

英文:

Add the pe-auto class to the &lt;label&gt; or the element with the tooltip (in this case, the &lt;button&gt;) to allow pointer events.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

new bootstrap.Tooltip(document.querySelector(&#39;[data-bs-toggle=&quot;tooltip&quot;]&#39;));

<!-- language: lang-html -->

&lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65&quot; crossorigin=&quot;anonymous&quot;&gt;
&lt;script src=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js&quot; integrity=&quot;sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4&quot; crossorigin=&quot;anonymous&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;form-floating&quot;&gt;
  &lt;input type=&quot;email&quot; class=&quot;form-control&quot; id=&quot;floatingInput&quot; placeholder=&quot;name@example.com&quot;&gt;
  &lt;label for=&quot;floatingInput&quot;&gt;
      Email address &lt;button class=&quot;btn badge text-bg-primary pe-auto&quot; type=&quot;button&quot; data-bs-toggle=&quot;tooltip&quot; title=&quot;Tooltip Title!&quot;&gt;Tooltip&lt;/button&gt;
  &lt;/label&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年3月31日 04:35:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75892784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定