最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Making an image link in a table - Stack Overflow

programmeradmin1浏览0评论

Does somebody know how to make a link form this image? Do I have to change "background" to "img src"? Or do I have to change the <a href>?

<a href="index.html"><td  height="117" colspan="4" background="afbeeldingen/klein-2kolom_04.gif"></a>&nbsp;</td>

Does somebody know how to make a link form this image? Do I have to change "background" to "img src"? Or do I have to change the <a href>?

<a href="index.html"><td  height="117" colspan="4" background="afbeeldingen/klein-2kolom_04.gif"></a>&nbsp;</td>
Share Improve this question asked Jan 11, 2012 at 13:40 kimkim 831 gold badge3 silver badges9 bronze badges 5
  • What have you tried? In the time you have taken to ask this question, you could have tested several different ways. – Oded Commented Jan 11, 2012 at 13:41
  • I tried different things with <a href>, it is Javascript, in HTML it will be work. I'm working with tables, so maybe that's the issue? – kim Commented Jan 11, 2012 at 13:43
  • Why did you end the <a> tag before you ended the <td> tag? – itdoesntwork Commented Jan 11, 2012 at 13:43
  • Why are you wrapping an anchor around a td? What exactly do you want to do here? Can you explain, in your questions, in clear terms, what you are trying to achieve? – Oded Commented Jan 11, 2012 at 13:44
  • I find out that it has nothing to do with the code. The image is integrated into another image, so I can not edit it. It is not my code and not my design, so one big puzzle. Thank you all for your help, but it's better to give up this piece of S***! – kim Commented Jan 11, 2012 at 14:12
Add a ment  | 

4 Answers 4

Reset to default 2

Backgrounds are backgrounds. Content is content. Links need to inform users about where they point and so require content. Table rows cannot have anchors as children. Table cells cannot have anchors as parents. The background attribute is obsolete.

<td>
    <a href="index.html">
        <img src="afbeeldingen/klein-2kolom_04.gif" alt="DON'T FORGET THIS">
    </a>
</td>

One way would be to use the onClick event:

<td height="117" colspan="4" background="afbeeldingen/klein-2kolom_04.gif" onclick="location.href='index.html';">&nbsp;</td>

To use a css based solution

<td  height="117" colspan="4" background="afbeeldingen/klein-2kolom_04.gif">
  <a href="index.html">&nbsp;</a>
</td>

Apply the following css

td a {
  display:block;
}

I tested and modified Bangline solution:

<table>
    <tr>
        <td height="117" colspan="4" background="afbeeldingen/klein-2kolom_04.gif">
          <a href="index.html">&nbsp;</a>
        </td>
    </tr>
    <tr><td>1</td><td>2</td><td>3</td><td>4</td></tr>
</table>

td a {
  display:block;
  height: 117px;
}

http://jsfiddle/gSVhP/2/

发布评论

评论列表(0)

  1. 暂无评论