2017-03-08 60 views
0

我有一個Rails 4.1.8應用程序,我試圖使用自定義avenir字體。 我已經添加了2個應用/資產/字體&應用/資產/樣式表的字體。我還在供應商/資產/樣式表/字體中添加了其中一些。 其中一個字體AvenirLTStd-Heavy.otf沒有得到應用程序。自定義字體不加載在Rails中

screen.scss 

@font-face { 
    font-family: "AvenirLTStd-Heavy"; 
    src: url('/assets/fonts/AvenirLTStd-Heavy.otf'); 
} 

.avenir-heavy { 
    font-family: "AvenirLTStd-Heavy"; 
    -webkit-font-smoothing: antialiased; 
    -moz-osx-font-smoothing: grayscale; 
} 

application.rb 

config.assets.paths << Rails.root.join(* %w(vendor assets bower_components)) 
config.assets.paths << Rails.root.join('app', 'assets', 'fonts') 
config.assets.paths << Rails.root.join('vendor', 'assets', 'stylesheets', 'fonts')  
config.assets.precompile += %w(.svg .eot .woff .ttf .otf) 

config/initializers/assets.rb 

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

我在做什麼錯?

+0

這個怎麼樣'/資產/ AvenirLTStd-Heavy.otf'? –

+0

試過。沒有工作。 – RamanSM

+0

對不起,如果你使用'.scss'文件,試試'asset-url('AvenirLTStd-Heavy.otf')',不要忘記在'config/initialize/assets.rb'上添加擴展文件 –

回答

0

包括預編譯路徑的資產字體路徑,只是使用的字體名稱&指定爲以下格式:

@font-face { 
    font-family: "AvenirLTStd-Heavy"; 
    src: url('AvenirLTStd-Heavy.otf') format("opentype"); 
}