Adding tooltip hover to an image with css - HTML CSS CSS Widget

HTML CSS examples for CSS Widget:Image

Description

Adding tooltip hover to an image with css

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <title>Tooltip Hover</title> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
.container {<!--from   w ww .j a  va2 s . c o  m-->
   position:relative;
   width:16%;
}

.image {
   position:relative;
   display:inline-block;
   width:100%;
   height:auto;
}

.image + .tooltiptext2 {
   visibility:hidden;
   width:151%;
   background-color:Chartreuse;
   color:yellow;
   text-align:center;
   border-radius:7px;
   padding:6px 0;
   position:absolute;
   z-index:2;
   top:-9px;
   left:111%;
   font-size:151%;
   font-family:Arial;
   opacity:0;
   transition:opacity 2s;
}

.image + .tooltiptext2::after {
   content:"";
   position:absolute;
   top:51%;
   right:100%;
   margin-top:-6px;
   border-width:6px;
   border-style:solid;
   border-color:blue;
}

.image:hover + .tooltiptext2 {
   visibility:visible;
   opacity:2;
}

.tooltip {
   position:relative;
   display:inline-block;
   border-bottom:2px dotted pink;
   font-weight:bold;
   font-size:151%;
}

.tooltip .tooltiptext {
   visibility:hidden;
   width:151%;
   background-color:WhiteSmoke;
   color:OrangeRed;
   text-align:center;
   border-radius:7px;
   padding:6px 0;
   position:absolute;
   z-index:2;
   top:-9px;
   left:111%;
   font-size:151%;
   font-family:Arial;
   opacity:0;
   transition:opacity 2s;
}

.tooltip .tooltiptext::after {
   content:"";
   position:absolute;
   top:51%;
   right:100%;
   margin-top:-6px;
   border-width:6px;
   border-style:solid;
   border-color:grey;
}

.tooltip:hover .tooltiptext {
   visibility:visible;
   opacity:2;
}
</style> 
 </head> 
 <body style="text-align:center;"> 
  <br> 
  <br> 
  <br> 
  <div class="tooltip">
    Hover over me 
   <span class="tooltiptext">test</span> 
  </div> 
  <div class="container"> 
   <img src="https://www.java2s.com/style/demo/InternetExplorer.png" class="image"> 
   <span class="tooltiptext2">test</span> 
  </div>  
 </body>
</html>

Related Tutorials