I have the following code:
<table>
<tr>
<td><a href="#">some text</a></td>
<td>some more text</td>
</tr>
</table>
I am trying to turn the whole row of this table into a hyperlink, however I do not want to use the JavaScript mouse event as i am restricted from using JavaScript. I have tried using CSS but only found ways to make an individual into a hyperlink by going: a href style="display block;"
, does anyone know a css way to turn the whole row into a hyperlink?
A linked table row is possible, but not with the standard <table> elements. You can do it using the display: table style properties.
To make the entire row as clickable in this case, one can use a link <a> tag to wrap its content.
You can't make the div a link itself, but you can make an <a> tag act as a block , the same behaviour a <div> has. You can then set the width and height on it. However, this doesn't make a 'div' into a link. It makes a link into a block element.
You need an a element to make a link, and you can't wrap an entire table row in one. The closest you can get is linking every table cell. Personally I'd just link one cell and use JavaScript to make the rest clickable.
No, you can't turn an element/field into a clickable link-following element/field with CSS only. You will need to either include an ANCHOR within each header/cell within the TR (and set the ANCHOR to display: block
so the entire cell is clickable), or use Javascript to make your TR or TR TH/TD's clickable/followable to the browser.
Example (of the ANCHOR approach):
http://jsfiddle.net/userdude/V9kj5/1/
tr a {
display: block;
}
tr td {
border: 1px solid #ddd;
width: 200px;
}
<table>
<tr>
<td><a href="http://www.google.com" target="_google">some text</a></td>
<td>some more text</td>
</tr>
<tr>
<td><a href="http://www.google.com" target="_google">some text</a></td>
<td><a href="http://www.google.com" target="_google">some more text</a></td>
</tr>
</table>
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