Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Bs5 Tooltip in Bootstrap

Bs5 Tooltip in Bootstrap

Absolutely! Here’s a quick guide on Bootstrap 5 Tooltips — small popups that display informative text when users hover, focus, or tap on an element.


? Bootstrap 5 Tooltips

Tooltips are used to provide additional context or information about an element on hover or focus.


1. Basic Tooltip Example

<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">  Hover me</button>
  • Add data-bs-toggle="tooltip" to enable tooltip on that element.

  • Use data-bs-placement to specify position: top, bottom, left, or right.

  • The title attribute contains the tooltip text.


2. Initialize Tooltips with JavaScript

Bootstrap 5 requires you to initialize tooltips via JS for them to work:

var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {  return new bootstrap.Tooltip(tooltipTriggerEl)})

This activates all tooltips on the page with data-bs-toggle="tooltip".


3. Tooltip Options

You can customize tooltips with options, e.g.,

var tooltip = new bootstrap.Tooltip(document.querySelector('#myTooltip'), {  placement: 'right',  trigger: 'hover focus',  delay: { "show": 500, "hide": 100 }});
  • placement: where the tooltip shows (top, bottom, left, right, auto)

  • trigger: how tooltip is triggered (hover, focus, click, manual)

  • delay: delay time in ms before showing/hiding


4. Example with Manual Trigger

<button id="manualTooltip" type="button" class="btn btn-info" title="Manual tooltip">  Click me</button><script>  var manualTooltip = new bootstrap.Tooltip(document.getElementById('manualTooltip'), {    trigger: 'manual'  });  document.getElementById('manualTooltip').addEventListener('click', function () {    manualTooltip.toggle();  });</script>

5. HTML Content in Tooltips

By default, tooltips escape HTML. To allow HTML:

var tooltip = new bootstrap.Tooltip(document.querySelector('#htmlTooltip'), {  html: true,  title: '<em>Italic</em> <u>and underlined</u>'});

Summary Table

Attribute/ClassDescription
data-bs-toggle="tooltip"Enables tooltip on element
data-bs-placementPosition of tooltip (top, bottom, etc.)
titleTooltip text
bootstrap.TooltipJS API to programmatically control tooltips
triggerEvents to trigger tooltip
delayDelay before showing/hiding
htmlEnable HTML inside tooltip content

If you want, I can help you build interactive tooltip demos or customize styles!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql