0

Here is an example jsfiddle which displays the span content when hovered over it. I want it not to hide when it is not hovered. It should hide when clicked somewhere outside.

http://jsfiddle.net/jn6re3aq/1/

#myChart {
  background-color: black;
}

#tooltip {
  display: none;
  position: relative;
  top: 8px;
  left: 10px;
  padding: 5px;
  margin: 10px;
  z-index: 100;
  background: #333;
  border: 1px solid #c0c0c0;
  opacity: 0.8;
  width: 300px;
  color: black;
  text-align: left;
}

#graphs:hover #tooltip {
  display: block;
}

#graphs {
  background-color: red;
}
<section id="graphs">
  <span id="tooltip">thisistest</span>
  <canvas id="myChart" width="550" height="350"></canvas>
</section>
mplungjan
  • 169,008
  • 28
  • 173
  • 236

1 Answers1

0

You can't do this with css, you have to use either javascript or jquery, simply on hover change the display to block.

Here is an example using jquery:

$("#graphs").hover(function(){
  $("#tooltip").css("display","block");
});
#myChart{
    background-color: black;
}
#tooltip {
    display: none;
    position: relative;
    padding: 5px; 
    margin: 10px;
    z-index: 100;
    background: #333;
    border: 1px solid #c0c0c0;
    opacity: 0.8; 
    width: 300px;
    color: black;
    text-align: left;
}

#graphs{
 background-color: red;   
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section id="graphs">
    <span id="tooltip">thisistest</span>    
    <canvas id="myChart" width="550" height="350"></canvas>
</section>
Mhd Alaa Alhaj
  • 2,438
  • 1
  • 11
  • 18