gpt4 book ai didi

github - 如何使用 github 托管网络字体?

转载 作者:行者123 更新时间:2023-12-01 22:49:57 34 4
gpt4 key购买 nike

更新:我使用了@brclz建议,像这样解决我的问题:

  1. 复制该系列每个字体文件的 GitHub 地址,

示例:

https://github.com/h-ibaldo/Raleway_Fixed_Numerals/blob/master/font/rawline-100.woff
  • 已更改 github.com在 URL 中 raw.githubusercontent.com ,
  • 示例:

    https://raw.githubusercontent.com/h-ibaldo/Raleway_Fixed_Numerals/blob/master/font/rawline-100.woff
  • 使用上述网址创建了一个 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 存储库,

  • 将字体嵌入 <head>我的 HTML 文档,链接样式表,同时将 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家族的网页字体版本,所有的文字数字都被字体的内衬数字替换,以一劳永逸地解决使用Raleway内衬数字的问题。

    我还为它准备了CSS样式表,它完美地解决了我的问题。知道这是其他人遇到的问题,我将通过 GitHub 提供字体文件和 CSS。

    我的问题是:如何使用 GitHub 来托管网络字体,以便打算使用的人不需要托管字体文件,而是导入它,就像 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,您可以通过在文件 URL 中使用域“raw.githubusercontent.com”(而不是 github.com)以原始格式显示源代码。

    因此,https://github.com/USERNAME/REPOSITORY/blob/master/FILE 变为 https://raw.githubusercontent.com/USERNAME/REPOSITORY/blob/master/文件

    但是,GitHub 将以纯文本 mime 类型提供文件,这可能会使 CSS 导入不起作用。

    我能想到的唯一解决方案是使用第三方服务,例如 Raw Git拥有真正的 CDN 行为。

    关于github - 如何使用 github 托管网络字体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39693837/

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