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

2 answers

2
points
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...

CSS:

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

HTML:

<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 almost 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 almost 7 years ago
  • perfect. ill test is after i eat. thx. canyonchase1 almost 7 years ago
1
point

sorry I forgot a quote after the link...

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