Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to turn a whole <tr> into a link

Tags:

html

css

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?

like image 625
mickwaffle Avatar asked Apr 26 '11 00:04

mickwaffle


People also ask

Can a TR be a link?

A linked table row is possible, but not with the standard <table> elements. You can do it using the display: table style properties.

How do you make a whole row in a table clickable as a link?

To make the entire row as clickable in this case, one can use a link <a> tag to wrap its content.

How do I turn an entire div into a link?

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.

How do you link an entire table in HTML?

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.


1 Answers

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>
like image 128
Jared Farrish Avatar answered Oct 18 '22 10:10

Jared Farrish