HTML Element Style How to - Hover image to show text caption








Question

We would like to know how to hover image to show text caption.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#hover {<!--  w w w  . j av a 2 s. c  o  m-->
  display: none;
}

#image:hover+#hover {
  display: block;
}
</style>
</head>
<body>
  <div id="image">
    <img
      src="http://www.java2s.com/style/download.png" />
  </div>
  <div id="hover">Test message</div>
</body>
</html>

The code above is rendered as follows: