【问题标题】:Bootstrap glyphicons aren't appearing when using Rails 5 and bootstrap-sass gem使用 Rails 5 和 bootstrap-sass gem 时没有出现引导字形图标
【发布时间】:2018-07-15 21:53:52
【问题描述】:

引导程序中的字形图标未显示在我的网站上。我去检查了 chrome 开发工具中的 Network 选项卡,并看到了这样的字体请求:

Request URL:http://localhost:3000/fonts/bootstrap/glyphicons-halflings-regular.woff2
Request Method:GET
Status Code:404 Not Found

所以我抓取了 glyphicon 字体并将它们放在app/assets/fonts/bootstrap 中,但这不起作用。我将fonts/ 文件夹移动到public/ 并再次尝试。 Glyphicons 有效,但这似乎是一种不好的做法。

如何将字体保留在app/assets/fonts 中并让它们正确加载?

【问题讨论】:

    标签: ruby-on-rails twitter-bootstrap sass ruby-on-rails-5


    【解决方案1】:

    我建议你使用:font-awesome-sass

    【讨论】:

    • 这很好,但我使用的是 glyphicons 字体,而不是很棒的字体。
    【解决方案2】:

    在我写这个问题的时候,我想通了。

    在您的引导主题文件中,查找以下行:

    //== Iconography
    //
    //## Specify custom location and filename of the included Glyphicons icon font. Useful for those including Bootstrap via Bower.
    
    //** Load fonts from this directory.
    
    // [converter] If $bootstrap-sass-asset-helper if used, provide path relative to the assets load path.
    // [converter] This is because some asset helpers, such as Sprockets, do not work with file-relative paths.
    $icon-font-path: if($bootstrap-sass-asset-helper, "bootstrap/", "../fonts/bootstrap/");
    

    我更改了变量$icon-font-path,所以它看起来像这样:

    $icon-font-path: if($bootstrap-sass-asset-helper, "bootstrap/", "../assets/fonts/bootstrap/");
    

    注意:所有字形字体文件都存在于app/assets/fonts/bootstrap

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 2017-11-05
      • 2015-11-19
      • 2013-12-24
      • 1970-01-01
      相关资源
      最近更新 更多