首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Ruby on Rails Bootstrap Glyphicons不工作

Ruby on Rails Bootstrap Glyphicons不工作
EN

Stack Overflow用户
提问于 2013-11-28 08:32:26
回答 15查看 59.2K关注 0票数 47

我已经在我的网站上添加了bootstrap。这是我正在使用的结构。(我无法删除bootstrap.css文件,因为我根据自己的喜好对其进行了修改)。

代码语言:javascript
复制
>app
>>assets
>>>fonts
>>>>4 glypicons icon files.
>>>images
>>>>N/A
>>>javascripts
>>>>Bootstrap.js (Jquery is installed in a gem)
>>>stylesheets
>>>>Bootstrap.css

一切都正确导入,但问题是字形图标不工作,我需要他们!

EN

回答 15

Stack Overflow用户

回答已采纳

发布于 2013-11-30 14:55:21

2015年11月编辑:我推荐这个gem:https://github.com/twbs/bootstrap-sass,它由Bootstrap社区积极维护,与Ruby on Rails配合得非常好。

我遇到了一个和你非常相似的问题,但我想通了!在您的bootstrap.css文件中找到此部分:

代码语言:javascript
复制
@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

并用/assets替换../fonts/。这就是你的最终代码的样子。

代码语言:javascript
复制
@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.woff') format('woff'), url('/assets/glyphicons-halflings-regular.ttf') format('truetype'), url('/assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

我希望这对你有帮助!

票数 100
EN

Stack Overflow用户

发布于 2014-07-03 21:42:44

如果您正在使用bootstrap-sass,并且遇到此问题,请尝试在您的某个scss文件中像这样导入bootstrap。如果你使用sass,只需转换语法:

代码语言:javascript
复制
@import "bootstrap-sprockets";
@import "bootstrap";
票数 45
EN

Stack Overflow用户

发布于 2013-11-28 08:50:29

我想你的asset pipeline可能有点问题

您想要将bootstrap.css更改为bootstrap.css.scss,然后替换它使用的位置

代码语言:javascript
复制
@font-face {
  font-family: 'Glyphicons Halflings';
  src: url('../fonts/glyphicons-halflings-regular.eot');
  src: url('../fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff') format('woff'), url('../fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('../fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

使用font-path (请参阅第2.3.2节- CSS和Sass)

代码语言:javascript
复制
@font-face {
  font-family: 'Glyphicons Halflings';
  src: font-path('glyphicons-halflings-regular.eot');
  src: font-path('glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
    font-path('glyphicons-halflings-regular.woff') format('woff'), 
    font-path('glyphicons-halflings-regular.ttf') format('truetype'), 
    font-path('glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

也在你的config/environments/production.rb

代码语言:javascript
复制
# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )

在你的config/application.rb

代码语言:javascript
复制
# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

查看另一个SO post,了解类似的问题

希望这能有所帮助

票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20255711

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档