How to Create a Link From an Entire HTML Table Cell?

Mary-Kate Olsen
Release: 2024-11-13 17:28:02
Original
1001 people have browsed it

How to Create a Link From an Entire HTML Table Cell?

Linking from a Table Cell ()

In HTML, it's possible to create hyperlinks from text within table cells. However, creating a link that spans the entire cell can be challenging.

To link the entire cell without JavaScript:

Preferred Method:

  1. Ensure the cell's content fills the entire height and width of the cell (but not including the borders).
  2. Wrap the content in an element with its href attribute set to the desired link.

Example:

<td>
  <a href="http://example.com">
    <div>
Copy after login

Note: This method is not semantically correct since is meant to be an inline element. However, it works in most browsers.

Alternative (Not Advised):

For Internet Explorer only, violate the HTML standard by directly linking the element.

Example:

<table border="1">
  <tr>
    <a href="http://example.com"><td width="200">Hello world</td></a>
  </tr>
</table>
Copy after login

Caution: This method is ill-advised because it's non-standard and will not work in other browsers.

The above is the detailed content of How to Create a Link From an Entire HTML Table Cell?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template