Languages
[Edit]
EN

CSS - create simple tooltip

0 points
Created by:
May87
427

In this article, we would like to show you how to create a simple tooltip using CSS.

1. Create a new style for tooltip class (using . selector),

2. set the tooltip to be invisible at the start using display: none;,

3. for the container (in our case div element) use the :hover pseudo-class with display: block; property inside to show up the tooltip text when you hover it.

Practical example:

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    div {
      height: 100px;
      width: 100px;
      background: deepskyblue;
    }

    .tooltip {
      position: relative;
      height: 20px;
      width: 120px;
      left: 100px;
      top: 80px;
      background: lightgray;
      display: none;  /* hide tooltip */
    }

    div:hover .tooltip {
      display: block;    /* show tooltip */
    }

  </style>
</head>
<body>
  <div>
    <div class="tooltip">Tooltip content...</div>
  </div>
</body>
</html>

References

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join