Custom fonts not showing - css

I have added new fonts to my app/assets/fonts/NewFont folder.
I have also added font files there: 1234.eot, 1234.woff2, 1234.woff, 1234.ttf
In my fonts.scss.css I have added:
#font-face {
font-family: 'NewFont';
src: font-url('NewFont/1234.eot');
src: font-url('NewFont/1234.eot?#iefix') format('embedded-opentype'),
font-url('NewFont/1234.woff2') format('woff2'),
font-url('NewFont/1234.woff') format('woff'),
font-url('NewFont/1234.ttf') format('truetype');
}
And when I use it for my body:
html, body {
font-family: 'NewFont', sans-serif;
}
And nothing happens. My font on the web-site is still showing the same. What am I missing?
I am using Ubuntu, but this shouldn't be dependent on the system in any-case.
I have tried replacing the font-url with assets-url, but no luck.
Should the font-family match some kind of font family that is already defined in the font files?
config/initializers/assets.rb:
Rails.application.config.assets.precompile += %w(1234.eot
1234.ttf
1234.woff
1234.woff2
fonts.css.scss)

You need to link to your assets folder:
#font-face {
font-family: '1234';
src: url('assets/fonts/NewFont/1234.eot');
...
...
}
More info on asset_path here: http://guides.rubyonrails.org/asset_pipeline.html

The answer was that I forgot to require the fonts file itself to the application.css file at the very top of the file:
*= require fonts
Side note:
Make sure that the fonts are in the public folder so production web-site can pick the fonts. For that purpose, update the:
src: font-url('NewFont/1234.eot')
to
src: url('/fonts/NewFont/1234.eot')
(in case you have moved the new font to the public/fonts/ directory)

Related

Font files were working in local environment but live site I'm getting 404 (Not Found)

I'm using some fonts in WordPress and I'm importing them like this
#font-face {
font-family: "Neutra";
src: url("/wp-content/themes/Sunterra/resources/fonts/Neutra-Text-Bold.otf");
}
This worked in my local dev environment but on the live server I'm getting 404 (Not Found)
The live server is not finding the font because of most likely a pathing or permission issue.
Try to use the full url to test. If that doesn't work, you should try to find out where the font is actually located and if it even exists on the live server.
#font-face {
font-family: "Neutra";
src: url("/wp-content/themes/Sunterra/resources/fonts/Neutra-Text-Bold.otf");
}
I think your font path was wrong. make sure your css file was link correctly something like that
#font-face {
font-family: 'iconfont';
src:
url('../fonts/iconfont.ttf?ukrc8w') format('truetype'),
url('../fonts/iconfont.woff?ukrc8w') format('woff'),
url('../fonts/iconfont.svg?ukrc8w#iconfont') format('svg');
font-weight: normal;
font-style: normal;
}
font file need to link with your css file
File stracture
-root
-css
-fonts.css
-fonts
-iconfont.ttf

custom font not loading on heroku with rails pipeline

Following this SO post, I changed all of my #font-face definitions to look like the following:
#font-face {
font-family: 'Pe-icon-7-stroke';
src:font-url('/assets/Pe-icon-7-stroke.eot?d7yf1v');
src:font-url('/assets/Pe-icon-7-stroke.eot?#iefixd7yf1v') format('embedded-opentype'),
font-url('/assets/Pe-icon-7-stroke.woff?d7yf1v') format('woff'),
font-url('/assets/Pe-icon-7-stroke.ttf?d7yf1v') format('truetype'),
font-url('/assets/Pe-icon-7-stroke.svg?d7yf1v#Pe-icon-7-stroke') format('svg');
font-weight: normal;
font-style: normal;
}
Where all of the font files are plassed in /assets/fonts/.
I also changed the file in which the above #font-face is declared from type .css to .scss. The fonts are still loading in development, but when I added the changes to git and pushed to my production site on heroku, the fonts still are not loading.
This may not be indicative of the problem I am having, but when I view my compiled assets on the live site, I see that for the definition of the font, there is written:
font-family:'Pe-icon-7-stroke';
src:url(/assets/Pe-icon-7-stroke.eot?d7yf1v);
as opposed to font-url it uses url (which is maybe how sass is converted into css, but may also mean that the old application.css is loading?)
https://kaf.herokuapp.com/assets/application-490d8d687dc0c9b526bf1348ca9a3a6f.css
For Reference, here is my complete assets directory on Github
https://github.com/ebbnormal/kaf/tree/master/app/assets/
Check out SASS asset helpers, specifically, this part:
Returns a url reference to the asset.
asset-url("rails.png") returns url(/assets/rails.png) As a
convenience, for each of the following asset classes there are
corresponding -path and -url helpers: image, font, video, audio,
javascript, stylesheet.
image-path("rails.png") returns "/assets/rails.png"
image-url("rails.png") returns url(/assets/rails.png)
It looks like you need to remove the /assets part in your font-url.
asset-url($relative-asset-path)
Returns a url reference to the asset.
asset-url("rails.png") returns url(/assets/rails.png)
As a convenience, for each of the following asset classes there are
corresponding -path and -url helpers:
image, font, video, audio,
javascript, stylesheet.
image-path("rails.png") returns "/assets/rails.png"
image-url("rails.png") returns url(/assets/rails.png)
https://github.com/rails/sass-rails
#font-face {
font-family: 'Pe-icon-7-stroke';
src: font-url('Pe-icon-7-stroke.eot?d7yf1v');
src: font-url('Pe-icon-7-stroke.eot?#iefixd7yf1v') format('embedded-opentype'),
font-url('Pe-icon-7-stroke.woff?d7yf1v') format('woff'),
font-url('Pe-icon-7-stroke.ttf?d7yf1v') format('truetype'),
font-url('Pe-icon-7-stroke.svg?d7yf1v#Pe-icon-7-stroke') format('svg');
font-weight: normal;
font-style: normal;
}
Although you might want to consider if you really need all those fallback formats today.
https://css-tricks.com/snippets/css/using-font-face/
http://caniuse.com/#feat=woff

Force browser to use woff font file

I have defined following #font-face rule:
#font-face {
font-family: "MyFont";
src: url(MyFont.eot);
src: url(MyFont.eot#iefix) format('embedded-opentype'),
url(MyFont.ttf) format('truetype'),
url(MyFont.woff) format('woff');
}
Since there were some bug in the woff font file I have fixed it and I need to test if font looks correct right now.
The problem is that i.e. Google Chrome uses ttf by default and I cannot modify the #font-face in the runtime - also I cannot modify the CSS on the server because of the complicated pipeline.
Can we force somehow the browser to use specific font file type ?
If you just want to test the woff file is working now, you can:
Try Firefox, I believe they prioritise WOFF, or
Temporarily change your #font-face code so Google Chrome only has WOFF as an option:
font-family: "MyFont";
src: url(MyFont.woff) format('woff');

Issue with using font with #font-face declaration and in general with applications

#font-face {
font-family: iconFont;
src: local(iconFont), url('fonts/iconFont.ttf') format('opentype');
}
The font file is not corrupt and installs fine in OSX etc. letting me preview it. But it won't render anything when I try to use it on a web page or even if I select it in illustrator it just switches to another font if I touch any key.
The font is for 'regular' and I have tried other options, but it won't work. Have tried typing with caps on/off etc. Using numpad, nothing. Have re-installed it and made sure there are no duplicates. It also won't work in Windows. Not sure if I need to change my css somehow or the fault lays with the font.
Here's a link to the font for anyone wanting to try. It's a bunch of metro icons. http://www2.zippyshare.com/v/23494573/file.html
Not sure if this will help, but this is the CSS I use, and it works fine. The webfonts directory is in the same directory as the css file, and includes three file types: .eot .ttf .woff
#font-face {
font-family: 'AvenirLT-Book';
src: url('webfonts/25EE2B_0_0.eot');
src: url('webfonts/25EE2B_0_0.eot?#iefix') format('embedded-opentype'), url('webfonts/25EE2B_0_0.woff') format('woff'), url('webfonts/25EE2B_0_0.ttf') format('truetype');
}
a typical class decleration:
.AvenirLT-Book {
font-family: AvenirLT-Book;
font-weight: normal;
font-style: normal;
}
perhaps you need to change the format to ('truetype') instead of ('opentype') ?

Overriding #font-face src URL?

We are using FontAwesome with Bootstrap. However, when we try to use FA with our custom minifier, it attempts to load the fonts from a relative path, which returns a 404, due to the way the minified URL structure is setup.
So we figured the best way to fix this was to add an additional CSS file to our minify list that would override the #font-face src URLs that FontAwesome's font uses. We basically just copied the #font-face definition from FontAwesome, and specified absolute URL locations.
However, now what happens is our correct URLs load the fonts AND the originally specified URLs from the FontAwesome CSS are attempted (resulting in the same 404 errors as before).
Are we doing something wrong, or is there really no way to override the #font-face src URLs so that 'upstream' definitions are totally ignored?
Simple override the font-family of the base CSS class:
.fa {
font-family: 'FontAwesome2' !important;
}
Then, paste/include and edit the font definition:
#font-face {
font-family: 'FontAwesome2';
src: url('//host.domain/yourpath/fontawesome-webfont.eot?v=3.1.0');
...
font-style: normal;
}
UPDATE: The "solution" below did not actually work... we did in fact have a typo, but in subsequent testing, this was still not the root cause, and we are still facing the issue.
The solution is to be VERY CAREFUL when overriding the #font-face, making sure to provide all of the same formats used in the original #font-face. Otherwise it appears the browser sees it as a different definition, and will try to download files referenced in both, rather than overriding it.
So here is the definition in FontAwesome's CSS, which is referenced first.
#font-face {
font-family: 'FontAwesome';
src: url('../font/fontawesome-webfont.eot?v=3.1.0');
src: url('../font/fontawesome-webfont.eot?#iefix&v=3.1.0') format('embedded-opentype'),
url('../font/fontawesome-webfont.woff?v=3.1.0') format('woff'),
url('../font/fontawesome-webfont.ttf?v=3.1.0') format('truetype'),
url('../font/fontawesome-webfont.svg#fontawesomeregular?v=3.1.0') format('svg');
font-weight: normal;
font-style: normal;
}
And when we tried to override, we accidentally dropped the "format('svg')" definition:
#font-face {
font-family: 'FontAwesome';
src: url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.eot?v=3.0.1');
src: url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.eot?#iefix&v=3.0.1') format('embedded-opentype'),
url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.woff?v=3.0.1') format('woff'),
url('//ourdomain.com/includes/font-awesome-3.1.x/font/fontawesome-webfont.ttf?v=3.0.1') format('truetype');
font-weight: normal;
font-style: normal;
}
Once we added the format('truetype') definition, we no longer experienced the additional hits that had resulted in 404s.
If you are using SCSS you likely have a main scss file in your src folder which contains an #import "font-awesome" that imports font-awesome from node_modules/font-awesome/scss/font-awesome.scss.
You can duplicate this font-awesome.scss file into your src folder and customise it. Then you can also duplicate font-awesome/scss/path.scss into your src folder too and customise that.
in main.scss (or whatever your initial scss file is called)
#import "path/custom-fontawesome";
in custom-fontawesome.scss
#import "~font-awesome/scss/variables";
#import "~font-awesome/scss/mixins";
#import "custom-fontawesome-path";
#import "~font-awesome/scss/core";
#import "~font-awesome/scss/larger";
#import "~font-awesome/scss/fixed-width";
#import "~font-awesome/scss/list";
#import "~font-awesome/scss/bordered-pulled";
#import "~font-awesome/scss/animated";
#import "~font-awesome/scss/rotated-flipped";
#import "~font-awesome/scss/stacked";
#import "~font-awesome/scss/icons";
#import "~font-awesome/scss/screen-reader";
in custom-fontawesome-path.scss
$fa-font-path: "../fonts-path";
#font-face {
font-family: 'FontAwesome';
src: url('#{$fa-font-path}/fontawesome-webfont.woff2?v=#{$fa-version}') format('woff2');
font-weight: normal;
font-style: normal;
}
You can customise the path to the font files by setting the $fa-font-path: "../fonts-path";

Resources