如何从< td>建立连结表单元格 [英] How can I make a link from a <td> table cell

查看:131
本文介绍了如何从< td>建立连结表单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下:

<td>
  some text
  <div>a div</div>
</td>

我想整个< td> ... < / td> 一个超链接。我喜欢不使用JavaScript。这是可能的吗?

I'd like to make the entire <td>...</td> a hyperlink. I'd prefer without the use of JavaScript. Is this possible?

推荐答案

是的,虽然不是字面上的< td& code>,但它是什么。简单的伎俩是,确保内容扩展到单元格的边界(它不会包括边框本身,虽然)。

Yes, that's possible, albeit not literally the <td>, but what's in it. The simple trick is, to make sure that the content extends to the borders of the cell (it won't include the borders itself though).

如前所述,语义不正确。 a 元素是一个内联元素,不应该用作块级元素。但是,这里有一个例子(但是JavaScript和一个td:hover CSS样式将更加整洁)在大多数浏览器中可用:

As already explained, this isn't semantically correct. An a element is an inline element and should not be used as block-level element. However, here's an example (but JavaScript plus a td:hover CSS style will be much neater) that works in most browsers:

<td>
  <a href="http://example.com">
    <div style="height:100%;width:100%">
      hello world
    </div>
  </a>
</td>



PS:实际上更改 a 在使用CSS的块级元素中在另一个解决方案中解释这个线程。它不会在IE6中工作得很好,但这没有消息;)

PS: it's actually neater to change a in a block-level element using CSS as explained in another solution in this thread. it won't work well in IE6 though, but that's no news ;)

如果你的世界只有Internet Explorer(很少,现在),你可以违反HTML标准,写这个,它会按预期工作,但会被高度皱眉和被视为不明智(你没有听说过这从我)。 IE以外的任何其他浏览器不会呈现链接,但会正确显示表格。

If your world is only Internet Explorer (rare, nowadays), you can violate the HTML standard and write this, it will work as expected, but will be highly frowned upon and be considered ill-advised (you haven't heard this from me). Any other browser than IE will not render the link, but will show the table correctly.

<table>
    <tr>
        <a href="http://example.com"><td  width="200">hello world</td></a>
    </tr>
</table>

这篇关于如何从&lt; td&gt;建立连结表单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆