To add the card animation to your Svelte app, you don't actually need to modify your app.html file. The app.html file is the main HTML template that Svelte uses to mount your application, and it typically doesn't need to be changed for adding components or animations.
Instead, you should place the card animation code in your App.svelte file (or create a new component for it). Here's how to integrate it:
1. Replace or modify your App.svelte file
The code you've provided is already a complete Svelte component. You can either:
- Replace the entire content of your
App.svelte with this code, or
- Create a new component (e.g.,
Card.svelte) and import it into your App.svelte
Option 1: Replace App.svelte
Simply copy the entire code you provided into your App.svelte file, replacing whatever is there.
Option 2: Create a separate component
- Create a new file
Card.svelte in your src folder and paste the code there.
- Then in your
App.svelte, you would import and use it like this:
<script>
import Card from './Card.svelte';
</script>
<main>
<h1>Welcome to my Svelte app</h1>
<Card />
</main>
About app.html
Your app.html should look something like this (the default from SvelteKit):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
%sveltekit.head%
</head>
<body>
<div id="svelte">%sveltekit.body%</div>
</body>
</html>
You typically don't need to modify this file unless you're adding global styles, scripts, or meta tags that should be available to all pages in your application.
Additional Notes
-
Make sure you have the necessary CSS variables (--bg-1, --fg-1, etc.) defined somewhere in your application. These might be in a global CSS file or in your component's style section.
-
If you're using SvelteKit (which is the default when you run npx sv create), the structure is slightly different from a basic Svelte app, but the component approach remains the same.
-
If you want the card to be full-screen, you might need to adjust the container styles or add some global styles to ensure the body and html elements take up the full viewport.