css - How do I reference a custom font file in my asset folder? -
with rails 5, how reference custom font file have uploaded? have placed file in
app/assets/fonts/chicagoflf-webfont.woff then in css file, have
@font-face { font-family: 'chicagoflfregular'; src: url('fonts/chicagoflf-webfont.woff2') format('woff2'), url('fonts/chicagoflf-webfont.woff') format('woff'); font-weight: normal; font-style: normal; } but don't see font loading, after restarting server. proper path should using in "url" field?
assuming using saas, can use either use font-url or asset-url call font. , considering placed custom fonts in app/assets/fonts, should able call fonts directly no prefix in path so
@font-face { font-family: 'chicagoflfregular'; src: font-url('chicagoflf-webfont.woff2') format('woff2'), font-url('chicagoflf-webfont.woff') format('woff'); font-weight: normal; font-style: normal; } or
@font-face { font-family: 'chicagoflfregular'; src: asset-url('chicagoflf-webfont.woff2') format('woff2'), asset-url('chicagoflf-webfont.woff') format('woff'); font-weight: normal; font-style: normal; } or
if not using saas, using url should able call font prefix assets not fonts so
@font-face { font-family: 'chicagoflfregular'; src: url('/assets/chicagoflf-webfont.woff2') format('woff2'), url('/assets/chicagoflf-webfont.woff') format('woff'); font-weight: normal; font-style: normal; } and if haven't pre-compiled assets, fonts won't appear. need pre-compile assets. example production environment do
rails_env=production bin/rails assets:precompile and don't forget restart server
Comments
Post a Comment