-1

I have read other questions (1, 2) asked on this site and how it is said that it is not possible to have an anchor inside another anchor, however I recently saw a website that is achieving this and I want to know how it's done.

You can see in the following website link where there are cards and each card is a link (whole thing wrapped in an anchor tag), but there are also other links inside the card.

https://opensea.io/collection/clonex

Looking at the HTML, you can see that there are actually two anchor tags (one nested inside the other). So this is not some JavaScript hack.

enter image description here

When I try the same HTML, the browser destructures my anchor tags. Anyone knows how this website manages to do this?

unrealapex
  • 578
  • 9
  • 23
Mahan_F
  • 7,839
  • 2
  • 14
  • 26

2 Answers2

0

According to https://css-tricks.com/nested-links/, you can possibly do that by just simply putting an anchor within an anchor by doing what is said

#one {
  background-color: yellow;
}

#two {
  background-color: lightgreen;
}
<a id="one" href="#linkone">
  Some text...
 <!--You can add a <br> tag here if you want-->
  <a id="two" href="#linktwo">
    Some more text...
  </a>
</a>

<!--The CSS is not necessary but is used to show this example-->

In the snippet above you can see it being done Notice that when you click on the links they are separate.

If it still does not work check your devtools if you do not find a solution you can search the web or browse youtube for an answer that is most clear to you.

Jason
  • 113
  • 1
  • 14
0

You can achieve same functionality by using click event on the card and show cursor as pointer:
Demo Codesandbox

goodCard.addEventListener('click', (e) => window.open(`https://www.google.com/`));

footLink.addEventListener('click', (e) => e.stopPropagation());
.card {
  padding-bottom: 20px;
  width: fit-content;
  font-size: 100px;
  background-color: rgb(251, 233, 199);
  position: relative;
  
  cursor: pointer;
}

.foot {
  position: absolute;
  bottom: 0;
  background-color: lightblue;
  width: 100%;
  font-size: initial;
}
<div id='goodCard' class='card'>
  
  <a id='footLink' href="http://www.gmail.com" target="_blank">
    <footer class="foot">Good Card</footer>
  </a>
</div>

For the demo I've used window.open(). If you are using some framework then you need to do it as the framework expects e.g. in react do this.


If you are curious about how to get anchors inside an anchor, then you can do it using javascript. See the demo link provided above. As everyone has already stated it's a bad idea. Don't do it.

the Hutt
  • 16,980
  • 2
  • 14
  • 44