Links within one another (nextjs)
Hey, having a problem with having link buttons within each other. When I try to give the bottom button with MdSettings icon props as={Link} and href it breaks the entire thing. But when i remove the as={Link} from the parent Card component, It works. how do you have two links within each other?
Solution:Jump to solution
In HTML it is illegal to have an anchor tag (link element) inside another link element, or more generally you cannot nest two interactive elements (so this also applies to buttons). From a UX perspective this makes sense, generally layered buttons result in poor user experiences, but sometimes are un-avoidable, hell even my project does this at times. The solution is to make your parent card a div element with a relative css atribute, and then have an inner div that takes up the entire space of the card as the link and a sibling component (another component on the same level) that is an absolutely positioned link that is placed wherever you want it to go. It should look something like this
```tsx
...
return (
<Card className='relative' ...>...
3 Replies
my goodness, what is you line length, can you make that snippet readable?
sorry, I made it more readable
Solution
In HTML it is illegal to have an anchor tag (link element) inside another link element, or more generally you cannot nest two interactive elements (so this also applies to buttons). From a UX perspective this makes sense, generally layered buttons result in poor user experiences, but sometimes are un-avoidable, hell even my project does this at times. The solution is to make your parent card a div element with a relative css atribute, and then have an inner div that takes up the entire space of the card as the link and a sibling component (another component on the same level) that is an absolutely positioned link that is placed wherever you want it to go. It should look something like this