I'm trying to build a table where each cell's content is wrapped with an A
tag set to full height and width, so that the entire cell is clickable.
But some of the cells need to have additional links in their content.
The solution that immediately jumps out is to nest the A
tags, like so:
<td>
<a href="#" class="cell" >
Officers include:
President, Vice president, Secretary, Treasurer,
<a href="#">7 others</a>
</a>
</td>
But nested A
tags are illegal. Is there any workaround that would allow me to achieve the desired effect?
If you chose not to use anchor links for clickable functional elements, then: Use cursor: pointer; so users get the cursor that looks like you can click like they are used to. Use the tabindex attribute on the element so keyboard users can tab to it. Define :hover , :active , and :focus styles.
Links and anchors defined by the A element must not be nested; an A element must not contain any other A elements. Since the DTD defines the LINK element to be empty, LINK elements may not be nested either.
You cannot nest 'a' tags.
You could use CSS or JavaScript. I would recommend just using CSS.
This works in my Firefox using CSS only. Basically I just made all child links (except the big one) have position: relative
and set their z-index
to higher than the large background link.
<div>
Hello, <a href="http://example.com/hello" class="normal">Bob</a>
<a href="http://example.com" class="big"></a>
</div>
div {
position: relative;
}
.big {
display: block;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 0;
}
.normal {
position: relative;
z-index: 1;
}
Attach a click event to the cell, and an event to all child links. Make sure child links events do not bubble up (stopPropagation()
).
You probably want something like...
<td>
<a href="#" class="cell" >
Officers include:
President, Vice president, Secretary, Treasurer,
</a>
<a href="#">7 others</a>
</td>
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