HTML Element Style How to - Hover to add border to image








Question

We would like to know how to hover to add border to image.

Answer


<!--from ww  w. ja v a 2s  .co m-->
<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#imgBorder:hover img, #imgBorder img:hover {
  border: 1px solid #000;
}
</style>
</head>
<body>
  <div id="imgBorder">
    <img src="http://www.java2s.com/style/download.png" />
  </div>
</body>
</html>

The code above is rendered as follows: