字体字形不适用于bootstrap 3和rails 4 [英] font glyphicons not working with bootstrap 3 and rails 4

本文介绍了字体字形不适用于bootstrap 3和rails 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使glyphicons与bootstrap 3和rails一起使用.我已经打乱了互联网,但找不到任何帮助.在我的bootstrap.css文件中,我有:

I cannot get glyphicons to work with bootstrap 3 and rails. I've scowered the internet and nothing i find helps. In my bootstrap.css file i have:

@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');
}

在application.rb中,我有:

In application.rb, I have:

config.assets.enabled = true  
config.assets.paths << "#{Rails.root}/app/assets/fonts" 
config.assets.precompile += %w( .svg .eot .woff .ttf )

我已经尝试运行:

rake资产:预编译RAILS_ENV = development

rake assets:precompile RAILS_ENV=development

在application.js中,我有:

In application.js I have:

//= require jquery
//= require jquery_ujs
//= require_tree .
//= require bootstrap

在application.css中,我有:

In application.css I have:

 *= require_self
 *= require_tree .
 *= require bootstrap
 */

我所有的字体都存储在素材资源/字体中

All my fonts are stored in assets/fonts

我已经看过以下内容,但没有一个起作用:

I've already looked at the following and none of them have worked:

Bootstrap 3 + Rails 4-某些Glyphicons不起作用

如何向Rails应用添加自定义字体?

我该如何解决?

推荐答案

如果您使用的是bootstrap-sass gem,请按照以下设置进行操作.如果不尝试,那是我使用过的最简单的引导程序设置.

If you're using bootstrap-sass gem, follow my setup below. If not give it a try, it's the easiest bootstrap setup that I've used.

按照我目前使用Rails版本4.1.6和4.1.8的方式

By the way I'm currently using rails Versions 4.1.6 and 4.1.8

两颗宝石

gem 'bootstrap-sass'
gem 'autoprefixer-rails'

您的Application.js如下所示(turbolinks可选)

Your Application.js should look like this below (turbolinks optional)

  /app/assets/javascripts/application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

样式表应具有这两个导入

Style sheet should have these two imports

/app/assets/stylesheets/application.scss

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

如果此设置对您不起作用,请尝试 字体路径 http://guides.rubyonrails.org/asset_pipeline.html#coding-links资产

if this setup doesn't work for you try font-path http://guides.rubyonrails.org/asset_pipeline.html#coding-links-to-assets

第2.3.2节css和sass

因此您的代码将来自:

url('/assets/glyphicons-halflings-regular.eot');

到 字体路径('glyphicons-halflings-regular.eot');

to font-path('glyphicons-halflings-regular.eot');

这篇关于字体字形不适用于bootstrap 3和rails 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆