html - table row like a link

Max Frai picture Max Frai · Sep 22, 2009 · Viewed 271.8k times · Source

I can't set my table row as link to something. I can use only css and html. I tried different things from div in row to something another, but still can't make it works.

Answer

Esteban Küber picture Esteban Küber · Sep 22, 2009

You have two ways to do this:

  • Using javascript:

    <tr onclick="document.location = 'links.html';">

  • Using anchors:

    <tr><td><a href="">text</a></td><td><a href="">text</a></td></tr>

I made the second work using:

table tr td a {
    display:block;
    height:100%;
    width:100%;
}

To get rid of the dead space between columns:

table tr td {
    padding-left: 0;
    padding-right: 0;
}

Here is a simple demo of the second example: DEMO