I have the following:
<td>
some text
<div>a div</div>
</td>
I'd like to make the entire <td>...</td>
a hyperlink. I'd prefer without the use of JavaScript. Is this possible?
2019-01-04 23:42发布
I have the following:
<td>
some text
<div>a div</div>
</td>
I'd like to make the entire <td>...</td>
a hyperlink. I'd prefer without the use of JavaScript. Is this possible?
You can creat the table you want, save it as an image and then use an image map to creat the link (this way you can put the coords of the hole td to make it in to a link).
Yes, that's possible, albeit not literally the
<td>
, but what's in it. The simple trick is, to make sure that the content extends to the borders of the cell (it won't include the borders itself though).As already explained, this isn't semantically correct. An
a
element is an inline element and should not be used as block-level element. However, here's an example (but JavaScript plus a td:hover CSS style will be much neater) that works in most browsers:PS: it's actually neater to change
a
in a block-level element using CSS as explained in another solution in this thread. it won't work well in IE6 though, but that's no news ;)Alternative (non-advised) solution
If your world is only Internet Explorer (rare, nowadays), you can violate the HTML standard and write this, it will work as expected, but will be highly frowned upon and be considered ill-advised (you haven't heard this from me). Any other browser than IE will not render the link, but will show the table correctly.
Use this code. It expands an
<a>
to fill the cell horizontally. To fill vertically, use theheight
property as well.That's not possible without javascript. Also, that won't be semantic markup. You should use link instead otherwise it is a matter of attaching
onclick
handler to<td>
to redirect to some other page.Here is my solution:
(LESS)
Like this you can still benefit from some table cell properties like
vertical-align
. (Tested on Chrome)I would recommend using an actual anchor element, and set it as block.
This will set the anchor to the same dimensions of the parent div.