css - Google 字体不再支持下载的文件?

标签 css truetype google-fonts

我已将 .ttf 文件从 google fonts 下载到我的本地 css 文件夹,但似乎无法正确加载它们。我尝试过这些方法:

CSS

@import url('./css/css?family=Cabin+Condensed:400,500,600,700');

@font-face {
    font-family: 'Cabin Condensed';
    font-style: normal;
    font-weight: 700;
    src: local('Cabin Condensed') format('truetype');
}

body, html {
    font-family: 'Cabin Condensed', sans-serif;
}

HTML

<link href="./css/css?family=Cabin+Condensed:400,500,600" rel="stylesheet">

我没有收到任何错误,但也没有显示字体。 奇怪的是,official docs甚至不要提及本地字体。

最佳答案

在我看来问题出在使用 local 路径,这需要在本地安装字体。

尝试删除 @import 并将 src: url 的后备添加到您的 src: local:

@font-face {
    font-family: 'Cabin Condensed';
    src: local('Cabin Condensed'), url(<path to the TTF file>);
}

例如:

@font-face {
    font-family: 'Cabin Condensed';
    src: local('Cabin Condensed'), url('/css/fonts/Cabin-Condensed.ttf');
}

关于css - Google 字体不再支持下载的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50129139/

相关文章:

Python:是否有 TrueType 字体库?

html - 为什么 Zap Chance 字体中有一个上标 esf?

google-fonts - font-family Work Sans 在 Google Chrome 中不起作用

css - 如何在包裹在 div 中的 <a> 标签之间留出空格

php - OCtoberCMS 博客插件 Rainlab

javascript - 如何摆脱 Javascript "Undefined"

html - Google 字体特殊字符在 PC 上显示正确,但在 HTML 中却无法显示?

javascript - 当之前的 div 充满 JQuery 时显示 div

php - 是否有用于将文本绘制为矢量轮廓的 PHP 库?

javascript - 如何在 NextJS 13 中导入自定义谷歌字体?链接标签不起作用