Why Firefox ignores custom font from #font-face? - css

Let’s say we have a font-face section like that
#font-face {
font-family: 'F';
src: url("/fonts/F.eot?") format("embedded-opentype");
src: local('?'),
url("/fonts/F.woff") format("woff"),
url("/fonts/F.ttf") format("truetype"),
url("/fonts/F.svg") format("svg");
font-weight: normal;
font-style: normal;
}
and a body style
body {
font-family: 'F' /*, sans-serif*/;
}
Now, if I uncomment sans-serif it will take priority over custom font despite the fact it is mentioned at the end. Why? How do I specify a back-up variant for those who can’t use downloadable webfonts?
===upd===
If in doubt why local('?') is used, look here http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/#smiley
I was wrong in my thinking that it is sans-serif breaking my CSS, here is actual code that shows custom 'F' font. If 'Trebuchet MS' will be uncommented, font-family drops to sans.
body {
font-family: 'F' /*, 'Trebuchet MS'*/ , sans-serif;
}

Your syntax seems to be slightly incorrect. The '?' at the end of the first 'src' property value is aimed towards fixing IE versions 6 through 8, but could actually be affecting Firefox. The correct syntax to use is:
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Source: http://www.fontspring.com/blog/further-hardening-of-the-bulletproof-syntax

Related

AMP font-face not working

I am currently stuck on my AMP site. I have a CSS file just for my AMP site and i set the font-face below for it.
I have to use the something like this because I need to access those font-files from my assets folder.
I am using Rails 5
#font-face {
font-family: 'Poppins';
font-style: normal;
font-weight: 400;
src:font-url('poppins-v5-latin-regular.eot'); /* IE9 Compat Modes */
src: local('Poppins Regular'), local('Poppins-Regular'),
font-url('poppins-v5-latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
font-url('poppins-v5-latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
font-url('poppins-v5-latin-regular.woff') format('woff'), /* Modern Browsers */
font-url('poppins-v5-latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
font-url('poppins-v5-latin-regular.svg#Poppins') format('svg'); /* Legacy iOS */
}
/* poppins-700 - latin */
#font-face {
font-family: 'Poppins';
font-style: normal;
font-weight: 700;
src:font-url('poppins-v5-latin-700.eot'); /* IE9 Compat Modes */
src: local('Poppins Bold'), local('Poppins-Bold'),
font-url('poppins-v5-latin-700.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
font-url('poppins-v5-latin-700.woff2') format('woff2'), /* Super Modern Browsers */
font-url('poppins-v5-latin-700.woff') format('woff'), /* Modern Browsers */
font-url('poppins-v5-latin-700.ttf') format('truetype'), /* Safari, Android, iOS */
font-url('poppins-v5-latin-700.svg#Poppins') format('svg'); /* Legacy iOS */
}
Best regards!
Fonts included via #font-face must be fetched via the HTTP or HTTPS scheme.
Source: https://www.ampproject.org/docs/design/responsive/custom_fonts
Via #font-face (no restrictions, all fonts allowed), You should use the full path.
Eg: http://somedomain.org/VeraSeBd.ttf or https://somedomain.org/VeraSeBd.ttf
<style amp-custom>
#font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("https://somedomain.org/VeraSeBd.ttf");
}
body {
font-family: "Bitstream Vera Serif Bold", serif;
}
</style>
Fonts included via #font-face must be fetched via the HTTP or HTTPS scheme.

#font-face not working only in Chrome Browser

I'm having trouble getting a font to display in Google Chrome (Version 51.0.2704.106 (64-bit))
Safari and Firefox work fine.
Here is the code I am using as an example.
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
font-weight: normal;
font-style: normal;
}
I have converted the font to woff2 on multiple sites. What might the problem be?
I recently had browser issues implementing #font-face on a website. Here were some of the solutions that worked:
Try using "" instead of '' for the url and format
Try not calling .svg last
Try specifying font-weight and font-style for each #font-face reference
Did you correctly reference the font-family later in the CSS?
With all the above changes, your code might look like this:
#font-face {
font-family: "MyWebFont";
src: url("webfont.eot"); /* IE9 Compat Modes */
src: url("webfont.eot?#iefix") format("embedded-opentype"), /* IE6-IE8 */
url("webfont.svg#svgFontName") format("svg"); /* Legacy iOS */
url("webfont.woff2") format("woff2"), /* Super Modern Browsers */
url("webfont.woff") format("woff"), /* Pretty Modern Browsers */
url("webfont.ttf") format("truetype") /* Safari, Android, iOS */
font-weight: normal;
font-style: normal;
}
Later on in the stylesheet:
body {
font-family: "MyWebFont";
}

Properly defining font-family in #font-face CSS rules

I recently came across the #font-family CSS rule as I was looking to use web fonts on my website.
Coming to the point, I've seen two variants in #font-family CSS code, which you can see below:
#font-face {
font-family: 'Droid Serif'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: normal; /* NOTE THIS LINE */
src: url('DroidSerif-Regular-webfont.eot');
src: url('DroidSerif-Regular-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifRegular'),
url('DroidSerif-Regular-webfont.woff') format('woff'),
url('DroidSerif-Regular-webfont.ttf') format('truetype'),
url('DroidSerif-Regular-webfont.svg#DroidSerifRegular') format('svg');
}
#font-face {
font-family: 'Droid Serif'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: italic; /* NOTE THIS LINE */
src: url('DroidSerif-Italic-webfont.eot');
src: url('DroidSerif-Italic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifItalic'),
url('DroidSerif-Italic-webfont.woff') format('woff'),
url('DroidSerif-Italic-webfont.ttf') format('truetype'),
url('DroidSerif-Italic-webfont.svg#DroidSerifItalic') format('svg');
}
and this is another:
#font-face {
font-family: 'DroidSerifRegular'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: normal; /* NOTE THIS LINE */
src: url('DroidSerif-Italic-webfont.eot');
src: url('DroidSerif-Italic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifItalic'),
url('DroidSerif-Italic-webfont.woff') format('woff'),
url('DroidSerif-Italic-webfont.ttf') format('truetype'),
url('DroidSerif-Italic-webfont.svg#DroidSerifItalic') format('svg');
}
#font-face {
font-family: 'DroidSerifItalic'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: normal; /* NOTE THIS LINE */
src: url('DroidSerif-Italic-webfont.eot');
src: url('DroidSerif-Italic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifItalic'),
url('DroidSerif-Italic-webfont.woff') format('woff'),
url('DroidSerif-Italic-webfont.ttf') format('truetype'),
url('DroidSerif-Italic-webfont.svg#DroidSerifItalic') format('svg');
}
Compare the lines that I've commented with /* NOTE THIS LINE */
The first variant is by Google Web Fonts, while the second one is by Font Squirrel. So, is one of these two wrong? (Just wanted to confirm, although both are very reliable sources.)
If acceptable, which one of the two would I be better off with?
the first example, though hard to believe, is correct; notice how the Droid Serif Regular is being declared as font weight normal and font style normal...how you'd expect a regular font to be displayed. the second declaration, it's calling in Droid Serif Italic, and setting it to to font-style:italic; this allows you to use multiple fonts within a family. If you wanted to add a bold font, you'd apply the same #font-face rule except you'd change font-weight:bold, while leaving font-style:normal and declaring the same font family.
fontsquirrel really does a great job with rendering #font-face rules, actually i've read about this technique there. surprised it's not being implemented. you can read more about this here: http://www.456bereastreet.com/archive/201012/font-face_tip_define_font-weight_and_font-style_to_keep_your_css_simple/

#font-face src: local - How to use the local font if the user already has it?

What is the right way to use #font-face so that the browser will not download the font if the user already have it?
I am using #font-face to define DejaVu, which is already installed on my system (linux).
Firefox is not downloading the font, but Chromium is downloading it every time!
My CSS code, based on font squirrel and that question look like this:
#font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuSerif-webfont.eot');
src: local('DejaVu Serif'), url('DejaVuSerif-webfont.woff') format('woff'), url('DejaVuSerif-webfont.ttf') format('truetype'), url('DejaVuSerif-webfont.svg#webfontCFu7RF0I') format('svg');
font-weight: normal;
font-style: normal;
}
/* ... #font-face definitions for italic and bold omitted ... */
#font-face {
font-family: 'DejaVu Serif';
src: url('DejaVuSerif-BoldItalic-webfont.eot');
src: local('DejaVu Serif Bold Italic'), url('DejaVuSerif-BoldItalic-webfont.woff') format('woff'), url('DejaVuSerif-BoldItalic-webfont.ttf') format('truetype'), url('DejaVuSerif-BoldItalic-webfont.svg#webfontQAewh7pf') format('svg');
font-weight: bold;
font-style: italic;
}
If you want to check for local files first do:
#font-face {
font-family: 'Green Sans Web';
src:
local('Green Web'),
local('GreenWeb-Regular'),
url('GreenWeb.ttf');
}
There is a more elaborate description of what to do here.
In case someone still need it:
Download the font you need from fonts.google.com, then set your CSS file:
#font-face { font-family: roboto-regular; src: url('./fonts/Roboto-Regular.ttf'); }
body {
font-family: roboto-regular;
}
Note: make sure the path to the TTF file is correct.
Rather an old discussion, but is someone comes to this place, here some more infos.
goto https://google-webfonts-helper.herokuapp.com/fonts
select there the font(s) you need/want
downlaod the selected fonts
copy the displayed css
The copied css code may not be 100% correct, so below what I have been using (and works perfectly):
/* open-sans-regular - vietnamese_latin_hebrew_greek_cyrillic */
#font-face {
font-family: 'Open Sans';
font-style: normal;
font-weight: 400;
font-display: swap;
src: url('fonts/open-sans-v34-vietnamese_latin_hebrew_greek_cyrillic-regular.eot'); /* IE9 Compat Modes */
src: local('😡');
src: url('fonts/open-sans-v34-vietnamese_latin_hebrew_greek_cyrillic-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('fonts/open-sans-v34-vietnamese_latin_hebrew_greek_cyrillic-regular.svg#OpenSans') format('svg'), /* Legacy iOS */
url('fonts/open-sans-v34-vietnamese_latin_hebrew_greek_cyrillic-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('fonts/open-sans-v34-vietnamese_latin_hebrew_greek_cyrillic-regular.woff') format('woff'), /* Modern Browsers */
url('fonts/open-sans-v34-vietnamese_latin_hebrew_greek_cyrillic-regular.woff2') format('woff2'); /* Super Modern Browsers */
}
Inside the edited code you can delete the comments (after each url(..) line.
And finally - as tipp: pack the source, in general the packed file is ~ 30% smaller (and your website will have the benefit).
Edit: updated code snippet to be actual.
The font ordering is based on the fact, that browsers read from bottom to top (see https://stackoverflow.com/a/22835957/3450837).
It includes also the "bulletproof" solution where a smiley (which one you want to use is up to you) is used (to prevent wasting bandwidth) - see https://www.paulirish.com/2009/bulletproof-font-face-implementation-syntax/

Don't apply font-family on text

I've used a font-family in css, but the font-family doesn't apply on text on the server. I've applyed the font-family as follows:
#font-face {
font-family: "SultanAdan";
font-style: normal;
font-weight: normal;
src: url("/WebsiteFiles/FontsSultanAdanBold.otf")format("opentype"),url("/WebsiteFiles/Fonts/SultanAdanBold.woff") format("woff"),url("/WebsiteFilesFontsSultanAdanBold.ttf")format("truetype"), url("/WebsiteFiles/Fonts/SultanAdanBold.svg")format("svg");
}
This is the method with the deepest support possible right now. The #font-face rule should be added to the stylesheet before any styles.
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Then use it to style elements like this:
body {
font-family: 'MyWebFont', Fallback, sans-serif;
}

Resources