在Ruby on Rails上使用@ font-face?
我想在Rails中包含我的自定义字体。
我的文件字体在app/assets/fonts/
。
我编辑了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'); }
我试图更改路径url('assets/fonts/fontello.eot');
url('fontello.eot');
太。
我编辑了配置:
# 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
但它不起作用。
我使用Rails 4.0.2。
您需要使用asset_path在css文件中使用资产(将erb扩展名添加到application.css文件中,然后在CSS规则中提供asset_path)
@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'); }
我鼓励你从类似的post中查看这个答案 –
首先将字体放入app / assets / fonts。 之后,您可以通过font-url(’font.eot’)帮助器将您的字体包含在sass / scss文件中。
否则,如果您决定使用它,asset_path仍应找到那里的字体。
将@ font-face文件集成到rails资产管道中
谢谢:
https://stackoverflow.com/users/120434/andrew-nesbitt
和