Table of Contents
CSS breakout button
How to make an entire card clickable without nested links
A basic example of how to make an entire card clickable while keeping a second link (like a tag or a "View" button) working on its own. Nested <a> elements are invalid HTML, so the title link stretches a pseudo-element over the card instead.
Basic usage
<div class="relative flex justify-between">
<a href="#" class="after:absolute after:inset-0 after:content-['']">
Card title
</a>
<a href="#" class="relative z-10">
View
</a>
</div>
- The card is
relative. This is the positioning context for the overlay. - The title link's
after:absolute after:inset-0 after:content-['']stretches an invisible hit area over the whole card. - The second link uses
relative z-10so it sits above that overlay and stays independently clickable.
If other content (like a description) sits on top of the overlay and blocks clicks, add pointer-events-none to that content and pointer-events-auto to the links.
For a more detailed example with a semantic <button> take a look at Andy Bell's article on Piccalilli.
Related snippets
Add Darkmode to sveltekit
How to add darkmode to a sveltekit project
Create images from HTML
How to convert html to an image on the server as a sveltekit API endpoint
Generate a pdf file
Different ways to generate a pdf file
Tailwind add custom font
How to add a custom font to tailwind