how to make a cell of table hyperlink

后端 未结 10 1461
盖世英雄少女心
盖世英雄少女心 2020-12-03 01:02

How can entire table cell be hyperlinked in html without javascript or jquery?

I tried to put href in td tag itself but its not working at least in chrome 18

相关标签:
10条回答
  • 2020-12-03 01:43

    I have also been looking for a solution, and just found this code on another site:

    <td style="cursor:pointer" onclick="location.href='mylink.html'">link</td>

    0 讨论(0)
  • 2020-12-03 01:46

    I have seen this before when people are trying to build a calendar. You want the cell linked but do not want to mess with anything else inside of it, try this and it might solve your problem.

    <tr>
    <td onClick="location.href='http://www.stackoverflow.com';">
    Cell content goes here
    </td>
    </tr>
    
    0 讨论(0)
  • 2020-12-03 01:48

    you can give an <a> tag the visual behavior of a table cell:

    HTML:

    <table>
      <tr>
        <a href="...">Cell 1</a>
        <td>Cell 2</td>
      </tr>
    </table>
    

    CSS:

    tr > a {
      display: table-cell;
    }
    
    0 讨论(0)
  • 2020-12-03 01:53

    Here is my solution:

    <td>
       <a href="/yourURL"></a>
       <div class="item-container">
          <img class="icon" src="/iconURL" />
          <p class="name">
             SomeText
          </p>
       </div>
    </td>
    

    (LESS)

    td {
      padding: 1%;
      vertical-align: bottom;
      position:relative;
    
         a {
            height: 100%;
            display: block;
            position: absolute;
            top:0;
            bottom:0;
            right:0;
            left:0;
           }
    
         .item-container {
             /*...*/
         }
    }
    

    Like this you can still benefit from some table cell properties like vertical-align.(Tested on Chrome)

    0 讨论(0)
提交回复
热议问题