admin管理员组文章数量:1026912
for a website that I want to create, I want to use the "Work Sans" Font from google. I downloaded "WorkSans-Black.ttf" file, created in the Folder "public" a subfolder "fonts" and threw the file in there. Following I have screenshoted the folder structure for you guys. Can anybody please help me, what are the next steps ?
for a website that I want to create, I want to use the "Work Sans" Font from google. I downloaded "WorkSans-Black.ttf" file, created in the Folder "public" a subfolder "fonts" and threw the file in there. Following I have screenshoted the folder structure for you guys. Can anybody please help me, what are the next steps ?
Share Improve this question edited Apr 13, 2021 at 16:59 Khashayar asked Apr 13, 2021 at 16:18 KhashayarKhashayar 472 silver badges15 bronze badges1 Answer
Reset to default 61. Download Font
Download the font and place it in the public/font
directory.
I would suggest using this tool to download Google Fonts: https://google-webfonts-helper.herokuapp./fonts/work-sans?subsets=latin
2. Extend Tailwind's font stack with your font
// tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ['Work Sans', ...defaultTheme.fontFamily.sans],
},
},
},
// ...
}
// tailwind.css
@tailwind base;
@tailwind ponents;
// Repeat this for all the weights you downladed
@font-face {
font-family: 'Work Sans';
font-style: normal;
font-weight: 400;
src: local(''),
url('public/fonts/work-sans-v9-latin-regular.woff2') format('woff2'),
url('public/fonts/work-sans-v9-latin-regular.woff') format('woff');
@font-face {
font-family: 'Work Sans';
font-style: normal;
font-weight: 100;
src: local(''),
url('public/fonts/work-sans-v9-latin-100.woff2') format('woff2'),
url('public/fonts/work-sans-v9-latin-100.woff') format('woff');
@tailwind utilities;
3. (Optional) Preload font for performance
// Ref.: https://kirazhang./posts/nextjs-custom-fonts
import Head from "next/head";
import Link from "next/link";
export default function Layout {
return (
<div>
<Head>
<link
rel="preload"
href="public/fonts/work-sans-v9-latin-regular.woff2"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="public/fonts/work-sans-v9-latin-100.woff2"
as="font"
crossOrigin=""
/>
</Head>
<body><Main /></body>
</div>
)
}
for a website that I want to create, I want to use the "Work Sans" Font from google. I downloaded "WorkSans-Black.ttf" file, created in the Folder "public" a subfolder "fonts" and threw the file in there. Following I have screenshoted the folder structure for you guys. Can anybody please help me, what are the next steps ?
for a website that I want to create, I want to use the "Work Sans" Font from google. I downloaded "WorkSans-Black.ttf" file, created in the Folder "public" a subfolder "fonts" and threw the file in there. Following I have screenshoted the folder structure for you guys. Can anybody please help me, what are the next steps ?
Share Improve this question edited Apr 13, 2021 at 16:59 Khashayar asked Apr 13, 2021 at 16:18 KhashayarKhashayar 472 silver badges15 bronze badges1 Answer
Reset to default 61. Download Font
Download the font and place it in the public/font
directory.
I would suggest using this tool to download Google Fonts: https://google-webfonts-helper.herokuapp./fonts/work-sans?subsets=latin
2. Extend Tailwind's font stack with your font
// tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme')
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ['Work Sans', ...defaultTheme.fontFamily.sans],
},
},
},
// ...
}
// tailwind.css
@tailwind base;
@tailwind ponents;
// Repeat this for all the weights you downladed
@font-face {
font-family: 'Work Sans';
font-style: normal;
font-weight: 400;
src: local(''),
url('public/fonts/work-sans-v9-latin-regular.woff2') format('woff2'),
url('public/fonts/work-sans-v9-latin-regular.woff') format('woff');
@font-face {
font-family: 'Work Sans';
font-style: normal;
font-weight: 100;
src: local(''),
url('public/fonts/work-sans-v9-latin-100.woff2') format('woff2'),
url('public/fonts/work-sans-v9-latin-100.woff') format('woff');
@tailwind utilities;
3. (Optional) Preload font for performance
// Ref.: https://kirazhang./posts/nextjs-custom-fonts
import Head from "next/head";
import Link from "next/link";
export default function Layout {
return (
<div>
<Head>
<link
rel="preload"
href="public/fonts/work-sans-v9-latin-regular.woff2"
as="font"
crossOrigin=""
/>
<link
rel="preload"
href="public/fonts/work-sans-v9-latin-100.woff2"
as="font"
crossOrigin=""
/>
</Head>
<body><Main /></body>
</div>
)
}
本文标签: javascriptHow to Add a google font to NextJs Project locally while using tailwind cssStack Overflow
版权声明:本文标题:javascript - How to Add a google font to Next.Js Project locally while using tailwind css - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745653152a2161438.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论