Skip to content

Commit 37e1d70

Browse files
author
Rich Harris
committed
svelte:head exercise
1 parent 94fcbe3 commit 37e1d70

File tree

15 files changed

+149
-13
lines changed

15 files changed

+149
-13
lines changed

content/tutorial/02-advanced-svelte/09-special-elements/08-svelte-head/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
title: <svelte:head>
33
---
44

5-
The `<svelte:head>` element allows you to insert elements inside the `<head>` of your document:
5+
The `<svelte:head>` element allows you to insert elements inside the `<head>` of your document. This is useful for things like `<title>` and `<meta>` tags, which are critical for good SEO.
6+
7+
Since those are quite hard to show in the context of this tutorial, we'll use it for a different purpose — loading stylesheets.
68

79
```svelte
810
/// file: App.svelte
9-
<svelte:head>
10-
<link rel="stylesheet" href="tutorial/dark-theme.css">
11-
</svelte:head>
11+
<script>
12+
const themes = ['margaritaville', 'retrowave', 'spaaaaace', 'halloween'];
13+
let selected = themes[0];
14+
</script>
15+
16+
+++<svelte:head>
17+
<link rel="stylesheet" href="/stylesheets/{selected}.css" />
18+
</svelte:head>+++
19+
20+
<h1>Welcome to my site!</h1>
1221
```
1322

1423
> In server-side rendering (SSR) mode, contents of `<svelte:head>` are returned separately from the rest of your HTML.
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1-
<svelte:head>
2-
<!-- elements go here -->
3-
</svelte:head>
1+
<script>
2+
const themes = ['margaritaville', 'retrowave', 'spaaaaace', 'halloween'];
3+
let selected = themes[0];
4+
</script>
45

5-
<h1>Hello world!</h1>
6+
<h1>Welcome to my site!</h1>
7+
8+
<select bind:value={selected}>
9+
<option disabled>choose a theme</option>
10+
11+
{#each themes as theme}
12+
<option>{theme}</option>
13+
{/each}
14+
</select>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
@font-face {
2+
font-family: 'Schlop';
3+
src: url('./fonts/shlop.woff2') format('woff2');
4+
}
5+
6+
body {
7+
display: flex;
8+
flex-direction: column;
9+
align-items: center;
10+
justify-content: center;
11+
background: url(./halloween.webp) no-repeat 50% 50% fixed;
12+
background-size: cover;
13+
}
14+
15+
h1 {
16+
font-size: min(8vw, 4rem);
17+
filter: drop-shadow(2px 2px 10px black);
18+
font-family: 'Schlop';
19+
background: linear-gradient(
20+
to bottom,
21+
hsl(0, 100%, 77%) 0%,
22+
hsl(0, 60%, 50%) 100%
23+
);
24+
-webkit-background-clip: text;
25+
-webkit-text-fill-color: transparent;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@font-face {
2+
font-family: 'Casablanca Antique';
3+
src: url('./fonts/casablanca-antique.woff2') format('woff2');
4+
}
5+
6+
body {
7+
display: flex;
8+
flex-direction: column;
9+
align-items: center;
10+
justify-content: center;
11+
background: url(./margaritaville.webp) no-repeat 50% 50% fixed;
12+
background-size: cover;
13+
}
14+
15+
h1 {
16+
font-size: min(8vw, 4rem);
17+
filter: drop-shadow(1px 1px 4px black) drop-shadow(1px 1px 20px black);
18+
font-family: 'Casablanca Antique';
19+
font-variant: small-caps;
20+
color: rgb(255, 226, 131);
21+
}

0 commit comments

Comments
 (0)