HTML Element Style How to - Add background-image to anchor








Question

We would like to know how to add background-image to anchor.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
#temp {<!--from  ww  w  .  ja  v a 2  s.com-->
  display: inline-block;
  background-image: url('http://www.java2s.com/style/download.png');
  width: 32px;
  height: 32px;
}
</style>
</head>
<body>
  <a href='#' id='temp'></a>
  <img src='http://www.java2s.com/style/download.png' />
</body>
</html>

The code above is rendered as follows: