在Ruby on Rails中使用@ font-face? [英] Using @font-face with Ruby on Rails?

查看:150
本文介绍了在Ruby on Rails中使用@ font-face?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的文件字体位于 app / assets / fonts /

我编辑了CSS:

 # /assets/stylesheets/application.css 

@ font-face {
font-family:'fontello';
src:url('fonts / fontello.eot');
src:url('fonts / fontello.eot#iefix')format('embedded-opentype'),
url('fonts / fontello.woff')format('woff'),
url('fonts / fontello.ttf')格式('truetype');

我试着改变路径 url('assets /fonts/fontello.eot'); url('fontello.eot');



我编辑了配置文件:

 #config / application.rb 

require File.expand_path('../ boot',__FILE__)
require'rails / all'

Bundler.require(:default,Rails.env)

模块Gui
class Application< Rails :: Application
config.assets.paths<< Rails.root.join('app','assets','fonts')
end
end

但它不起作用。



我使用Rails 4.0.2。

解决方案

使用asset_path在css文件中使用资源(在您的application.css文件中添加erb扩展名,然后asset_path在您的CSS规则中可用)

pre $ code> @ font-face {
font-family:'fontello';
src:url('<%= asset_path(fontello.eot)%>');
src:url('<%= asset_path(fontello.eot#iefix)%>')format('embedded-opentype'),
url('<%= asset_path( 'fontello.woff)%>')format('woff'),
url('<%= asset_path(fontello.ttf)%>')format('truetype');
}


I am trying to include my custom font in Rails.

My file fonts are in app/assets/fonts/.

I edited CSS:

# in app/assets/stylesheets/application.css

@font-face {
  font-family: 'fontello';
  src: url('fonts/fontello.eot');
  src: url('fonts/fontello.eot#iefix')format('embedded-opentype'),
       url('fonts/fontello.woff') format('woff'),
       url('fonts/fontello.ttf') format('truetype');
}

I tried to change the path url('assets/fonts/fontello.eot'); url('fontello.eot'); too.

I edited the config:

# in config/application.rb

require File.expand_path('../boot', __FILE__)
require 'rails/all'

Bundler.require(:default, Rails.env)

module Gui
  class Application < Rails::Application
    config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
  end
end

But it doesn't work.

I use Rails 4.0.2.

解决方案

You need to use asset_path for use an asset in a css file ( add erb extension to your application.css file then asset_path are available in your CSS rules)

@font-face {
  font-family: 'fontello';
  src: url('<%= asset_path("fontello.eot") %>');
  src: url('<%= asset_path("fontello.eot#iefix") %>') format('embedded-opentype'),
       url('<%= asset_path("fontello.woff") %>') format('woff'),
       url('<%= asset_path("fontello.ttf") %>') format('truetype');
}

这篇关于在Ruby on Rails中使用@ font-face?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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