Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove tooltip delay for HTML element [duplicate]

Tags:

html

css

@Mukyuu helpfully flagged a duplicate question, but it is quite old and the correct answer in 2019 may be very different. For instance, @Andy Hoffman has suggested a workaround that was not viable years ago.

This question is similar, but not the same.

Our web page contains multiple tooltips. There's a noticeable 1-2 second lag before the first tooltip appears (on Chrome). After this first one appears, subsequent tooltips appear nearly instantly as you hover over other elements.

To be clear, tooltip refers to the value in the title attribute of an element like this:

<input type="button" title="Click" value="My Button">

Is there a way to make all tooltips appear instantly?

like image 917
Crashalot Avatar asked Apr 02 '19 07:04

Crashalot


People also ask

How do I make tooltip disappear after 5 seconds?

It's set on 5 seconds. Instead add the data-trigger='manual' attribute to each of elements, we can add option in initialisation script:'$(document). ready(function() { $('[data-toggle="tooltip"]'). tooltip({ trigger:'hover manual', //...})})'

How do I prevent title attribute from showing tooltip?

There's no way to disable the default browser behaviour, which is to show the title attribute as a "tooltip" in the browser itself. You'll need to resort to some javascript, it could even be as simple as setting the title to blank on hover, and replacing it on mouse out....

Which HTML attribute can be used to show a tooltip?

HTML title Attribute The title attribute specifies extra information about an element. The information is most often shown as a tooltip text when the mouse moves over the element. The title attribute can be used on any HTML element (it will validate on any HTML element.


1 Answers

You can use an element's pseudo content to display a tooltip on hover. Note, pseudo content does not work with inputs but does work with button, as in the following example.

.my-button {
  position: relative;
}

.my-button:hover::after {
  position: absolute;
  content: attr(data-tooltip);
  bottom: -2.5em;
  right: -1em;
  background-color: #333;
  color: white;
  padding: .25em .5em;
}
<input type="button" title="Click" value="My Button">

<button class="my-button" data-tooltip="Click">My Button</button>

Update

As a workaround for input, include a wrapper div, and use the data attribute of that div instead of the child input.

.input-wrapper {
  position: relative;
  display: inline-block;
}

.input-wrapper:hover::after {
  position: absolute;
  content: attr(data-tooltip);
  bottom: -2.5em;
  right: -1em;
  background-color: #333;
  color: white;
  padding: .25em .5em;
  font-size: .8em;
}
<div class="input-wrapper" data-tooltip="Click">
  <input type="button" value="My Button">
</div>
like image 200
Andy Hoffman Avatar answered Oct 18 '22 20:10

Andy Hoffman