Bootstrap5 prompt box


Release date:2024-01-10 Update date:2024-01-12 Editor:admin View counts:82

Label:

Bootstrap5 prompt box

The prompt box is a small pop-up window that appears when the mouse moves over the element and disappears when the mouse moves outside the element.

How to create a prompt box

By adding to elements data-bs-toggle="tooltip" let’s create a prompt box.

title property is what is displayed in the prompt box:

<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="I am the prompt content!">Move the mouse over to me</button>

Note: the prompt box should be written in the initialization code of JavaScript: then call on the specified element tooltip() method.

The following examples can use prompt boxes anywhere in the document:

Example

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

Specify the location of the prompt box

By default, the prompt box is displayed above the element.

You can use the ‘data bs placement’ attribute to set the direction of the prompt box display: top , bottom , left or right :

Example

<a href="#" data-bs-toggle="tooltip" data-bs-placement="top" title="I am the prompt content!">Move the mouse over to me</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="bottom" title="I am the prompt content!">Move the mouse over to me</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="left" title="I am the prompt content!">Move the mouse over to me</a>
<a href="#" data-bs-toggle="tooltip" data-bs-placement="right" title="I am the prompt content!">Move the mouse over to me</a>

Powered by TorCMS (https://github.com/bukun/TorCMS).