HTML Element Style How to - Overlay an image with a link








Question

We would like to know how to overlay an image with a link.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.mainLinks {<!--from  ww w . j a va2  s.c  om-->
  padding-right: 30px;
  padding-bottom: 5px;
  background: #fff url(http://www.java2s.com/style/download.png)
    no-repeat right top;
  text-decoration: none;
}
</style>
</head>
<body>
  <p>
    <a class="mainLinks" href="#">Test</a>
  </p>
</body>
</html>

The code above is rendered as follows: