Page Widget How to - Create CSS Tooltip








Question

We would like to know how to create CSS Tooltip.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.tooltip {<!-- w  w  w  .j  a  va 2  s.  c  om-->
  display: inline;
  position: relative;
}

.tooltip:hover:after {
  background: #333;
  background: rgba(0, 0, 0, .8);
  border-radius: 5px;
  bottom: 26px;
  color: #fff;
  content: attr(title);
  left: 20%;
  padding: 5px 15px;
  position: absolute;
  z-index: 98;
  width: 220px;
  content: attr(title);
}

.tooltip:hover:before {
  border: solid;
  border-color: #333 transparent;
  border-width: 6px 6px 0 6px;
  bottom: 20px;
  content: "";
  left: 50%;
  position: absolute;
  z-index: 99;
}
</style>
</head>
<body>
  <br>
  <br>
  <br>
  <br>
  <a title="This is some information for our tooltip." class="tooltip">CSS3
    Tooltip</a>
  <br>
  <br>
  <br>
  <br>
  <a title="Another information for our tooltip." class="tooltip">CSS3
    Tooltip</a>
</body>
</html>

The code above is rendered as follows: