gpt4 book ai didi

gatsby - 使用 gatsby 谷歌字体插件时仍然会出现无样式文本

转载 作者:行者123 更新时间:2023-12-05 03:50:32 27 4
gpt4 key购买 nike

我在 gatsby 中的主要字体是在 index.scss 文件夹中定义的,就像这样在 body 标签中。

body {
font-family: "Trebuchet MS", "Helvetica";
font-size: 16px;
}

对于标题,我想使用 google 字体,并且我尝试使用这些插件进行预加载:

 {
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [`Sacramento`],
display: "swap",
},
},
{
resolve: `gatsby-plugin-prefetch-google-fonts`,
options: {
fonts: [
{
family: `Sacramento`,
variants: [`400`],
},
],
},
},
{
resolve: "gatsby-plugin-web-font-loader",
options: {
google: {
families: ["Sacramento"],
},
},
},

在 css 中定义了字体,但在生产中而不是在本地开发中仍然会出现无样式文本。

.title {
font-family: "Sacramento", cursive;
}

最佳答案

您的.title 类是正确的。

但是,由于您将字体显示为 swap ( font-display: swap ),它首先加载具有默认排版的字体,直到它被渲染并被您的 CSS 覆盖。这避免了 CSS 渲染阻止您的网络加载,提高了您的网络性能,但如果您真的想避免闪烁,只需在选项对象中添加 display: block 即可:

{
resolve: `gatsby-plugin-google-fonts`,
options: {
fonts: [
`Sacramento`
],
display: 'block'
}
}

关于gatsby - 使用 gatsby 谷歌字体插件时仍然会出现无样式文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63416304/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com