I know it is possible to link an entire table cell with CSS.
.tableClass td a{ display: block; }
Is there a way to apply a link to an entire table row?
Using <a> tag inside <td> One more way to make the whole row clickable is to add an <a> inside every <td> element. Along with it add hover to the row which we want to make clickable and use display: block property to anchor to make the whole row clickable.
Allowing a table row to be a link is not as simple as one might think. This article explains what the main issue is with making links out of table rows, provides some solutions to the problem, showcase some real-world examples, and question whether having a table row as a link is something that should even be done.
You can put the anchor inside the td and then set the anchor to display:block and it will fill the table cell. e.g. However if your design is more complicated than that then you can't put block level elements inside that anchor. You would then need to use javascript for IE6 as it only understands hover on anchors.
I agree with Matti. Would be easy to do with some simple javascript. A quick jquery example would be something like this:
<tr> <td><a href="http://www.example.com/">example</a></td> <td>another cell</td> <td>one more</td> </tr>
and
$('tr').click( function() { window.location = $(this).find('a').attr('href'); }).hover( function() { $(this).toggleClass('hover'); });
then in your CSS
tr.hover { cursor: pointer; /* whatever other hover styles you want */ }
Use the ::before
pseudo element. This way only you don't have to deal with Javascript or creating links for each cell. Using the following table
structure
<table> <tr> <td><a href="http://domain.tld" class="rowlink">Cell</a></td> <td>Cell</td> <td>Cell</td> </tr> </table>
all we have to do is create a block element spanning the entire width of the table using ::before
on the desired link (.rowlink
) in this case.
table { position: relative; } .rowlink::before { content: ""; display: block; position: absolute; left: 0; width: 100%; height: 1.5em; /* don't forget to set the height! */ }
demo
The ::before
is highlighted in red in the demo so you can see what it's doing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With