Home > Web Front-end > CSS Tutorial > How to Make Table Cell Links Clickable Across the Entire Row Height?

How to Make Table Cell Links Clickable Across the Entire Row Height?

Mary-Kate Olsen
Release: 2024-11-03 13:12:03
Original
668 people have browsed it

How to Make Table Cell Links Clickable Across the Entire Row Height?

Filling Table Row Vertically with Cell Links

In HTML tables, users expect to be able to click anywhere within a cell to follow the associated link. However, when table cells span multiple lines and others are single-lined, the single-lined cells may not occupy the entire vertical space of the row.

To remedy this issue, setting the display property of table cell links to block is a common approach. However, this may not fully resolve the problem in all cases.

Solution

To ensure that table cell links fill the entire row height, implement the following CSS rule:

<code class="css">td {
    overflow: hidden;
}
td a {
    display: block;
    margin: -10em;
    padding: 10em;
}</code>
Copy after login

By setting an arbitrarily large negative margin and equal padding on the block element, the link will span the entire vertical space of the table row. The overflow property is set to hidden on the parent td element to prevent the excessive padding from spilling outside the cell.

Example

<code class="html"><td style="overflow: hidden;">
    <a style="display: block; margin: -10em; padding: 10em;" href="http://www.google.com/">Cell 1</a>
</td></code>
Copy after login

This updated CSS will ensure that table cells containing links are always clickable across their entire height, regardless of the number of lines they span.

The above is the detailed content of How to Make Table Cell Links Clickable Across the Entire Row Height?. 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