Youss
Youss

Reputation: 4212

Table link not working in Firefox, IE8

I have a table which has a background image(sprite). The td of the table functions as a link relative to the position of the sprite image. I have it like this:

CSS:

table.populair {
    background-image:url(populair.png);
    background-position:27px 27px;
    background-repeat:no-repeat;
}


table td {
    border:solid 1px #ccc;
    border-radius:4px;
    cursor:pointer;
}

td a{
    display:block;
    width: 105%;
    height: 105%;
    margin-left: -3px;
    margin-top: -2px;
        z-index:15;
}

HTML:

<table class="populair" border="0" bordercolor="#FFCC00" width="647" height="322" cellpadding="0" cellspacing="27">
            <tr>
                <td><a href="http://www.link.com/"></a>
                </td>
                <td><a href="http://www.link.com/"></a>
                </td>
                <td><a href="http://www.link.com/"></a>
                </td>
                <td><a href="http://www.link.com/"></a>
                </td>
                <td class="none">
                </td>
            </tr>
            </table>

It works in Chrome (the links are clickable) but not in Firefox and IE8. The weird this is that if I change the td a from percentage to pixels it seems to work, but that ruins my sprite position...So what can I do to make the links work?

Upvotes: 0

Views: 1101

Answers (1)

The Alpha
The Alpha

Reputation: 146191

You have to assign the width and height of the parent element(td) to use % for child item.

table.populair {
    background-image:url(populair.png);
    background-position:27px 27px;
    background-repeat:no-repeat;
}


table tr td {
    border:solid 1px #ccc;
    border-radius:4px;
    display:table-cell;
    width: 10%;
    height: 100%;
}

table tr td a{
    display:block;
    width: 100%;
    height: 100%;
    margin-left: -3px;
    margin-top: -2px;
    z-index:15;
}​

DEMO.

Upvotes: 1

Related Questions