Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:03,000 --> 00:00:05,580
We've seen how to include a custom
2
00:00:05,580 --> 00:00:08,007
font in our Next.js application.
3
00:00:08,084 --> 00:00:11,667
And so far we used it as a "className",
4
00:00:11,667 --> 00:00:14,938
that we need to add to any element containing
5
00:00:14,938 --> 00:00:17,990
text that we want to display in that font.
6
00:00:18,063 --> 00:00:21,328
Now, in our project we use Tailwind
7
00:00:21,328 --> 00:00:23,193
CSS for most styles.
8
00:00:23,287 --> 00:00:25,886
And Tailwind already configures
9
00:00:25,886 --> 00:00:27,731
some fonts by default.
10
00:00:27,815 --> 00:00:30,301
In fact, it also lets us define
11
00:00:30,301 --> 00:00:31,985
our own custom fonts,
12
00:00:32,064 --> 00:00:35,539
in the "tailwind.config.js" file.
13
00:00:35,539 --> 00:00:38,367
Now, the Next.js font module
14
00:00:38,367 --> 00:00:42,424
can also be used together with Tailwind CSS.
15
00:00:42,424 --> 00:00:44,643
We can configure a custom font
16
00:00:44,643 --> 00:00:46,197
like in this example.
17
00:00:46,271 --> 00:00:48,517
When initializing it, we can
18
00:00:48,517 --> 00:00:50,764
assign it to a CSS variable,
19
00:00:50,844 --> 00:00:52,756
like "--font-inter".
20
00:00:52,756 --> 00:00:56,082
Then we need to add that variable to the
21
00:00:56,082 --> 00:00:58,910
CSS classes of the "html" element,
22
00:00:58,993 --> 00:01:02,095
to make it available globally in our application.
23
00:01:02,095 --> 00:01:05,459
And finally we need to configure Tailwind
24
00:01:05,459 --> 00:01:08,988
to use that CSS variable as the font.
25
00:01:08,988 --> 00:01:11,128
In this case it's using it as
26
00:01:11,128 --> 00:01:13,047
the default "sans" family,
27
00:01:13,120 --> 00:01:16,270
but we can also add a custom font name.
28
00:01:16,270 --> 00:01:19,268
This way, we'll then be able to use our font
29
00:01:19,268 --> 00:01:22,944
just like any other Tailwind utility class.
30
00:01:22,944 --> 00:01:25,338
Let's see how this works in practice,
31
00:01:25,338 --> 00:01:27,341
if we go back to our application.
32
00:01:27,498 --> 00:01:30,860
So, when initializing the Orbitron font,
33
00:01:30,860 --> 00:01:33,364
we can set a "variable" option,
34
00:01:33,364 --> 00:01:35,960
with the name of the CSS variable
35
00:01:35,960 --> 00:01:38,477
we'll use to refer to this font.
36
00:01:38,556 --> 00:01:40,973
By the way, if you're not familiar
37
00:01:40,973 --> 00:01:42,325
with CSS variables,
38
00:01:42,396 --> 00:01:45,710
I've included a link to an article explaining them
39
00:01:45,710 --> 00:01:47,909
in this lecture's Resources.
40
00:01:47,909 --> 00:01:51,629
But, after initializing our font with a variable,
41
00:01:51,629 --> 00:01:55,371
we need to define that CSS variable globally
42
00:01:55,371 --> 00:01:59,411
by adding it to the top-level "html" element.
43
00:01:59,411 --> 00:02:02,978
Here we need to import our "orbitron" font,
44
00:02:02,978 --> 00:02:07,368
and pass "orbitron.variable" as the CSS class.
45
00:02:07,368 --> 00:02:11,164
Again, this will define the right CSS variable.
46
00:02:11,164 --> 00:02:14,387
The next step is to configure Tailwind.
47
00:02:14,387 --> 00:02:17,000
Here we can "extend" the "theme",
48
00:02:17,000 --> 00:02:20,625
and customize the "fontFamily" mappings.
49
00:02:20,625 --> 00:02:23,859
We can add our own family, called "orbitron",
50
00:02:23,859 --> 00:02:26,601
and as value we need to pass an array,
51
00:02:26,601 --> 00:02:29,451
with the possible options to choose from.
52
00:02:29,451 --> 00:02:31,612
As the first choice we want
53
00:02:31,612 --> 00:02:33,453
to use the CSS variable
54
00:02:33,533 --> 00:02:36,411
that we defined when initializing the font.
55
00:02:36,793 --> 00:02:39,385
We need to use exactly the same string
56
00:02:39,385 --> 00:02:41,432
in the Tailwind configuration.
57
00:02:41,500 --> 00:02:43,623
Now, it's a good idea to also
58
00:02:43,623 --> 00:02:45,599
provide a fall-back option,
59
00:02:45,673 --> 00:02:48,329
just in case for whatever reason our
60
00:02:48,329 --> 00:02:50,469
custom font cannot be loaded.
61
00:02:50,543 --> 00:02:53,879
We could put "sans-serif" as the second option,
62
00:02:53,879 --> 00:02:56,621
that should always be available in any browser.
63
00:02:56,621 --> 00:03:00,963
Ok, we can now save this "tailwind.config.js"
64
00:03:00,963 --> 00:03:01,446
file.
65
00:03:01,542 --> 00:03:04,024
And with this, our custom font will
66
00:03:04,024 --> 00:03:06,364
be available as a Tailwind class,
67
00:03:06,435 --> 00:03:08,324
which means it will be easier
68
00:03:08,324 --> 00:03:10,149
to use it in our components.
69
00:03:10,214 --> 00:03:13,695
We can simply add it to the CSS class list,
70
00:03:13,695 --> 00:03:15,671
as "font-orbitron".
71
00:03:15,671 --> 00:03:17,880
You can see that it's even available
72
00:03:17,880 --> 00:03:19,291
in the auto-completion.
73
00:03:19,352 --> 00:03:23,268
That's because we added "orbitron" as a "fontFamily"
74
00:03:23,268 --> 00:03:25,527
in the Tailwind configuration.
75
00:03:25,602 --> 00:03:27,863
And this means we no longer need
76
00:03:27,863 --> 00:03:30,125
to include "orbitron.className",
77
00:03:30,195 --> 00:03:31,786
as an expression.
78
00:03:31,786 --> 00:03:35,128
So we can also use a regular string as the value,
79
00:03:35,128 --> 00:03:37,989
and we can remove the import as well.
80
00:03:37,989 --> 00:03:40,470
If we save this change, the Heading
81
00:03:40,470 --> 00:03:42,950
should still use the Orbitron font.
82
00:03:43,021 --> 00:03:45,395
So, you can see that, with this approach,
83
00:03:45,395 --> 00:03:48,541
there's an initial bit of configuration required,
84
00:03:48,541 --> 00:03:50,450
but then using the font in
85
00:03:50,450 --> 00:03:52,286
our components is easier.
86
00:03:52,359 --> 00:03:54,826
In fact, suppose we want to apply
87
00:03:54,826 --> 00:03:56,696
it to our NavBar as well,
88
00:03:56,770 --> 00:03:58,461
for some of our links.
89
00:03:58,461 --> 00:04:00,476
Let's change "Home" to say
90
00:04:00,476 --> 00:04:02,413
"Indie Gamer" by the way,
91
00:04:02,491 --> 00:04:04,861
since that's the name of our website.
92
00:04:04,861 --> 00:04:08,430
Now we could use "font-orbitron" for this text.
93
00:04:08,430 --> 00:04:11,043
We don't need to import anything,
94
00:04:11,043 --> 00:04:14,063
it's just a Tailwind utility class.
95
00:04:14,063 --> 00:04:17,140
You can see in the page, in the top-left corner,
96
00:04:17,140 --> 00:04:20,581
that "Indie Gamer" now looks more like a logo.
97
00:04:20,581 --> 00:04:23,076
Maybe we could make it bold as well,
98
00:04:23,076 --> 00:04:25,377
so it will stand out even more.
99
00:04:25,377 --> 00:04:26,926
And we could also push the
100
00:04:26,926 --> 00:04:28,416
other links to the right,
101
00:04:28,476 --> 00:04:31,573
by setting the "margin-left" to "auto".
102
00:04:31,573 --> 00:04:34,440
You can see that the "Reviews" and "About"
103
00:04:34,440 --> 00:04:36,284
links are now on the right.
104
00:04:36,352 --> 00:04:38,825
Now, if we go to the Reviews page,
105
00:04:38,825 --> 00:04:41,887
we could change the card titles as well,
106
00:04:41,887 --> 00:04:44,404
to use the Orbitron font.
107
00:04:44,404 --> 00:04:46,578
Let me open the right file.
108
00:04:47,504 --> 00:04:50,604
Again, we just need to add "font-orbitron"
109
00:04:50,604 --> 00:04:52,080
to the "h2" element,
110
00:04:52,154 --> 00:04:55,727
and it will be used for the "Hollow Knight" text.
111
00:04:55,727 --> 00:04:56,925
That looks good,
112
00:04:56,925 --> 00:04:59,955
but maybe we can make it a bit bolder,
113
00:04:59,955 --> 00:05:01,630
with "font-semibold".
114
00:05:01,709 --> 00:05:03,409
Ok, I like that.
115
00:05:03,409 --> 00:05:05,459
Let's just apply the same styles
116
00:05:05,459 --> 00:05:07,124
to the other item as well,
117
00:05:07,188 --> 00:05:10,465
and "Stardew Valley" will use the same font.
118
00:05:10,465 --> 00:05:13,692
Good. You can see how, using a custom font
119
00:05:13,692 --> 00:05:16,765
gives a bit more character to our pages.
120
00:05:16,842 --> 00:05:18,776
And, when using Tailwind,
121
00:05:18,776 --> 00:05:21,276
it's very easy to apply a custom
122
00:05:21,276 --> 00:05:22,838
font to any element.
123
00:05:22,916 --> 00:05:25,445
We just need to configure it first,
124
00:05:25,445 --> 00:05:26,674
like we did here.
9041
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.