I need to make a div an image which is a link. I just forgot. Thx in advance.

2 answers

This was chosen as the best answer

If this DIV has a background image I recommend using an 'a' tag instead of using a DIV...


a.image { background: url(image.jpg); width:200px; height:300px; display:block; cursor:pointer; }


<a href="http://www.url.com" class="image"></a>

You want to do it this way so that it validates. You could put and 'a' tag outside the 'div' and set it to display:block, but then it won't validate as proper code.

Answered about 7 years ago by Juan Di Diego
  • I agree with Juan. Do note that `display:block` is VERY important for it to work. `inline-block` will do so if you want inline layout. o.k.w about 7 years ago
  • perfect. ill test is after i eat. thx. canyonchase1 about 7 years ago

sorry I forgot a quote after the link...

<a href="http://www.url.com" class="image"></a>
Answered about 7 years ago by Juan Di Diego
  • Updated the code and formatting for you in the original answer. +1 from me! o.k.w about 7 years ago