如何放入<a> tag?</a> <table> </table>

时间:2012-08-10 11:17:16

标签: html css

table置于a标记内是否是一个好方法?为什么链接在包装表时不起作用?

<a href="/place">
  <table>
    <tr>
      <td>
        <span class="place-icon" />
      </td>
      <td> 
        My place name
      </td>
    </tr>
  </table>
</a>

3 个答案:

答案 0 :(得分:5)

  

我需要实现下一个html

不,你没有,也不应该。真。它是无效的,非语义的,并且(可能最重要的)由于这些原因而无法可靠地工作。

如果您想要的只是一张图片和一些文字(已链接),请使用以下内容:

<a href="/place" class="button">My Place Name</a>

.button {
    display: inline-block;
    background-image: url();
    background-position: 2px 2px;
    padding-left: 16px; /* size of image */
}

以下是一个有效的例子:http://jsfiddle.net/RvTp3/

根据评论,这是另一个示例,显示文本换行时与垂直中间对齐的图像:http://jsfiddle.net/RvTp3/1/

答案 1 :(得分:1)

在我看来,你只想要一个带有图标和文字的链接,两者都链接到/放置,而你只使用<table>进行布局,对吧?为什么不摆脱桌面并使用css进行布局?

答案 2 :(得分:1)

不是。你不应该。

如果您想在表格中启用点击。那么你可以通过将click事件附加到表来实现。

 <table  onclick="window.location='yoururl'">
    <tr>
      <td>
        <span class="place-icon" />
      </td>
      <td> 
        My place name
      </td>
    </tr>
  </table>