HTML Form How to - Show Buttons over Image on Hover








Question

We would like to know how to show Buttons over Image on Hover.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
div.show-image {<!--   www .  j a  va  2 s.c o m-->
  position: relative;
  float: left;
  margin: 5px;
}

div.show-image:hover img {
  opacity: 0.5;
}

div.show-image:hover input {
  display: block;
}

div.show-image input {
  position: absolute;
  display: none;
}

div.show-image input.update {
  top: 0;
  left: 0;
}

div.show-image input.delete {
  top: 0;
  left: 79%;
}
</style>
</head>
<body>
  <h2>Hover on the Image to see the Buttons</h2>
  <div class="show-image">
    <img src="http://placehold.it/400x200" />
    <input class="update" type="button" value="Update" /> <input
      class="delete" type="button" value="Delete" />
  </div>
</body>
</html>

The code above is rendered as follows: