一些Glyphicons无效

时间:2016-01-17 07:25:38

标签: ruby-on-rails twitter-bootstrap-3

我知道stackoverflow充满了这些问题,但我找到的解决方案并没有解决我的问题,首先看来所有响应都假设你已经安装了一些gem来使用bootstrap(比如bootstrap-sass)我唯一做的就是下载它并将内容放入适当的文件夹中,如here所述。

所以答案的一半是提出这些命令:

@import "bootstrap-sprockets"
@import "bootstrap"

在我的scss或sass文件中(我没有)。

另一半说我必须改变这个:

@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-face {
  font-family: 'Glyphicons Halflings';
  src: url('../assets/glyphicons-halflings-regular.eot');
  src: url('../assets/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');
}

这对我不起作用......

那么,任何人都有另一种解决方案吗?

1 个答案:

答案 0 :(得分:0)

  

所以答案的一半是放置这些命令

如果您read the docs,您会看到bootstrap提倡将@import "bootstrap"指令添加到您的主SCSS / SASS文件中(可能{ {1}}),所以您需要将其包含在主文件中:

application.scss

这将在您的主application.sass文件中包含#app/assets/stylesheets/application.sass @import bootstrap 文件,允许您从中引用类等。

这与任何字体问题无关。您可以阅读sprockets manifest directives以获取有关其工作原理的更多信息。

<强>字体

对于您的字体问题,您遇到了一些问题。

  
      
  1. 您只需一个 bootstrap.sass gem
  2.   
  3. 您无需手动将文件包含在任何地方(它们包含在宝石中)
  4.   

强烈建议使用rails-assets直接从bootstrap repo拉出来(保持清洁):

bootstrap

这会将所有相应的#Gemfile source "https://rails-assets.org" gem 'rails-assets-bootstrap', ">= 4.0.0.alpha.2" 文件放在您的系统上,然后您可以通过资产管道引用该文件:

bootstrap

应该包含所有字体。

为了确保它们正常工作,您最好为生产模式预编译资产:

#app/assets/stylesheets/application.sass
@import bootstrap