【问题标题】:Ruby on Rails webfont not displaying locallyRuby on Rails webfont 未在本地显示
【发布时间】:2017-11-17 03:46:00
【问题描述】:

我正在使用 Rails 3.2.22 并使用 .woff 和 .woff2 文件安装了新字体。但字体似乎无法仅在本地显示。在资产被预编译和捆绑后,当我部署到我们的暂存环境时,字体显示良好。我还可以按照我本地编译的 CSS 用来尝试显示字体的 url,该链接下载正确的文件。

字体文件包含在“app/assets/fonts”文件夹中,我的application.rb中有这个

config.assets.paths << Rails.root.join("app", "assets", "fonts")

我将字体拉入 Sass,如下所示:

// Custom Font Faces
@font-face {
  font-family: 'Museo Sans Rounded';
  src: font-url('MuseoSansRounded-500-webfont.woff2') format('woff2'),
       font-url('MuseoSansRounded-500-webfont.woff') format('woff');
  font-weight: 500;
  font-style: normal;
}

@font-face {
  font-family: 'Museo Sans Rounded';
  src: font-url('MuseoSansRounded-700-webfont.woff2') format('woff2'),
       font-url('MuseoSansRounded-700-webfont.woff') format('woff');
  font-weight: 700;
  font-style: normal;
}

任何线索为什么这不显示在本地?

【问题讨论】:

标签: css ruby-on-rails ruby fonts


【解决方案1】:

尝试在本地编译资产。请按照以下步骤操作:

config/environments/production.rb

config.assets.compile = true

然后运行命令:

RAILS_ENV=production rake assets:precompile

并对其进行测试。

【讨论】:

    【解决方案2】:

    试试这个方法,这是“Glyphicons Halflings”的一个工作示例

    @font-face {
    font-family: 'Glyphicons Halflings';
    src: url('/assets/glyphicons-halflings-regular.eot');
    src: url('/assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('/assets/glyphicons-halflings-regular.woff2') format('woff2'), url('/assets/glyphicons-halflings-regular.woff') format('woff'), url('assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg')
    

    }

    【讨论】:

      猜你喜欢
      • 2018-12-20
      • 1970-01-01
      • 2011-01-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多