-
I want to make a table row a link. This is a code sandbox where I have demonstrated both the examples. Can someone help me achieve with tailwindcss, please? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 4 replies
-
Inserting an You can use |
Beta Was this translation helpful? Give feedback.
-
I found this resource very good at explaining this problem and how to resolve it: https://robertcooper.me/post/table-row-links#solution-3-use-css-grid-to-create-a-table |
Beta Was this translation helpful? Give feedback.
-
I'll provide a pure CSS solution to achieve this. <tr class="relative">
<td>Cell 1</td>
<td><a href="#" class="after:absolute after:inset-0">Click me</a></td>
</tr> https://codepen.io/sntran/pen/zYQBbNY The idea is to extend the |
Beta Was this translation helpful? Give feedback.
-
Since Safari does not support A cross-browser way to do this is to put the https://codesandbox.io/p/devbox/xpqzxv <table className="overflow-hidden">
<tr>
<td>
first cell
</td>
<td class="relative">
<a href="#" class="after:absolute after:-left-[2000px] after:w-[9999px]">
Click me
</a>
</td>
<td>
something
</td>
<td>
something else
</td>
</tr>
</table> |
Beta Was this translation helpful? Give feedback.
Inserting an
<a>
around<tr>
in a<table>
is not valid html. See "Permitted content" in https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tableYou can use
onclick
handler on the<tr>
and use a bit of JavaScript, or my preferred way, use<div>
tags and use Tailwind's.table
,.table-row
,.table-cell
classes to give them table behavior and styling.https://tailwindcss.com/docs/display#class-reference