Add Hover Text Without Javascript Like We Hover on a User's Reputation

Add Hover Text Without Javascript Like We Hover on a User's Reputation

In stackoverflow, when we hover on a user's reputation we see a text. I have seen this at many places and the source code tells me that it can be done without js. And i tried and got only this-

 <div="text">hover me</div>

5 Answers

Use the title attribute, for example:

<div title="them's hoverin' words">hover me</div>

or:

<span title="them's hoverin' words">hover me</span>
9

The title attribute also works well with other html elements, for example a link...

<a title="hover text" ng-href="{{getUrl()}}"> download link
</a>

Often i reach for the abbreviation html tag in this situation.

<abbr title="Hover">Text</abbr>

1

You're looking for tooltip

For the basic tooltip, you want:

<div title="This is my tooltip">

For a fancier javascript version, you can look into:

The above link gives you 12 options for tooltips.

This can also be done in CSS, for more customisability:

.hoverable {
  position: relative;
}

.hoverable>.hoverable__tooltip {
  display: none;
}

.hoverable:hover>.hoverable__tooltip {
  display: inline;
  position: absolute;
  top: 1em;
  left: 1em;
  background: #888;
  border: 1px solid black;
}
<div class="hoverable">
  <span class="hoverable__main">Main text</span>
  <span class="hoverable__tooltip">Hover text</span>
</div>

(Obviously, styling can be improved)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.