【发布时间】:2017-02-03 06:22:57
【问题描述】:
更新:我使用了@brclz 的建议,这样解决了我的问题:
- 复制了家族各字体文件的GitHub地址,
例子:
https://github.com/h-ibaldo/Raleway_Fixed_Numerals/blob/master/font/rawline-100.woff
- 将网址中的
github.com更改为raw.githubusercontent.com,
例子:
https://raw.githubusercontent.com/h-ibaldo/Raleway_Fixed_Numerals/blob/master/font/rawline-100.woff
- 使用上述 URL 创建了一个 CSS 样式表,声明该系列的所有字体粗细和样式,
例子:
@font-face {
font-family: 'rawline';
src: url('https://cdn.rawgit.com/h-ibaldo/Raleway_Fixed_Numerals/master/font/rawline-100.eot');
src: url('https://cdn.rawgit.com/h-ibaldo/Raleway_Fixed_Numerals/master/font/rawline-100.eot?#iefix') format('embedded-opentype'),
url('https://cdn.rawgit.com/h-ibaldo/Raleway_Fixed_Numerals/master/font/rawline-100.woff2') format('woff2'),
url('https://cdn.rawgit.com/h-ibaldo/Raleway_Fixed_Numerals/master/font/rawline-100.woff') format('woff'),
url('https://cdn.rawgit.com/h-ibaldo/Raleway_Fixed_Numerals/master/font/rawline-100.ttf') format('truetype'),
url('https://cdn.rawgit.com/h-ibaldo/Raleway_Fixed_Numerals/master/font/rawline-100.svg') format('svg');
font-weight: 100;
font-style: normal;
}
将样式表拉到字体的 GitHub 存储库,
-
将字体嵌入到我的 HTML 文档的
<head>中,链接样式表,还将 URL 中的“github.com”更改为“raw.githubusercontent.com”,如下所示:
<link href="https://raw.githubusercontent.com/h-ibaldo/Raleway_Fixed_Numerals/master/css/rawline.css" rel="stylesheet">
- 然后我使用 CSS 规则来指定字体的系列、粗细和样式,
例子:
font-family: 'rawline', sans-serif;
font-weight: 100;
font-style: italic;
效果很好。
-
我还尝试使用
@import将其导入另一个样式表,如下所示:@import 'https://raw.githubusercontent.com/h-ibaldo/Raleway_Fixed_Numerals/master/css/rawline.css';
它也有效。
这是最终的 GitHub 项目,如果您想查看它:
https://github.com/h-ibaldo/Raleway_Fixed_Numerals
我刚刚做了一个Raleway系列的webfont版本,其中所有的文字数字都被字体的衬里数字所取代,以一劳永逸地解决使用Raleway的衬里数字的问题。
我还为它准备了 CSS 样式表,它很好地解决了我的问题。知道这是其他人的问题,我将通过 GitHub 提供字体文件和 CSS。
我的问题是:我如何使用 GitHub 来托管 webfont,以便人们打算使用不需要托管字体文件,而是导入它,例如 Google Fonts @import 选项,例如:
@import 'https://fonts.googleapis.com/css?family=Raleway:400,700,900';
或者像 Fontawesome 用脚本做的那样:
<script src="https://use.fontawesome.com/28e4d6013b.js"></script>
有什么想法吗?
【问题讨论】:
标签: github fonts webfonts truetype google-webfonts