【问题标题】:How to correctly include webfonts into a bootstrap-sass project?如何正确地将 webfonts 包含到 bootstrap-sass 项目中?
【发布时间】:2015-09-21 21:04:48
【问题描述】:

我创建了一个bootstrap-sass project with yeoman generator

我想添加一个网络字体,每次编译我的 scss 代码时都会收到以下错误:

错误 app/src/stylesheets/main.scss(第 25 行:文件未找到或无法找到 阅读: /Users/username/Desktop/testfolder/fonts/../fonts/nexa-webfont/nexaheavy-webfont.woff)

我怎样才能摆脱不必要的 ../testfolder/fonts/.. 文件夹在路径中吗?

我的 main.scss 看起来像这样:

// VER: 0.1

/* OVERRIDDEN BOOTSTRAP VARIABLES */
$icon-font-path: "../fonts/bootstrap/";

/* STANDARD INCLUDES */
@import "bootstrap-compass";
@import "bootstrap-sprockets";
@import "bootstrap";
@import "compass/css3";

/* CUSTOM FONT IMPORT */
@include font-face(
  "Nexa Heavy",
  inline-font-files(
    '../fonts/nexa-webfont/nexaheavy-webfont.woff', woff,
    '../fonts/nexa-webfont/nexaheavy-webfont.ttf', ttf,
    '../fonts/nexa-webfont/nexaheavy-webfont.svg', svg),
    '../fonts/nexa-webfont/nexaheavy-webfont.eot',
  normal, // font-weight
  normal  // font-style
);


/* CUSTOM INCLUDES */
@import "custom-variables";
@import "common";
@import "navigation";
@import "footer";

@import "pages/home";

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap compass-sass webfonts bootstrap-sass


    【解决方案1】:

    当我们导入我们使用的字体时:

    @font-face {
      font-family: "diogenesregular";
      src: asset-url("assets/diogenes-webfont.eot");
      src: asset-url("assets/diogenes-webfont.eot?#iefix") format("embedded-opentype"),
      asset-url("assets/diogenes-webfont.woff2") format("woff2"),
      asset-url("assets/diogenes-webfont.woff") format("woff"),
      asset-url("assets/diogenes-webfont.ttf") format("truetype"),
      asset-url("assets/diogenes-webfont.svg#diogenesregular") format("svg");
      font-weight: normal;
      font-style: normal;
    }
    

    虽然不太确定您的设置或字体工具包。 我们将所有字体放在app/assets/fonts 中,然后将上述字体导入app/assets/stylesheets/fonts.scss,然后将此文件导入application.scss

    【讨论】:

    • 这适用于 Chrome 和 Safari,但不适用于 Firefox。有什么想法吗?
    • 可以给你预编译的问题:/
    • 你能发布你当前的导入块吗?
    猜你喜欢
    • 2019-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 2016-07-28
    • 2012-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多