I have a small static website and I need to move it on an USB to make it possible to open it via this USB.
Via CSS I defined those rules for the fonts (Is a custom font):
#font-face {
font-family: 'MyFont_SerifReg';
src: url('/assets/fonts/MyFontSerifReg.ttf') format('truetype');
src: url('/assets/fonts/MyFontSerifReg.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSerifReg.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSerifReg.woff') format('woff'); /* Pretty Modern Browsers */
}
#font-face {
font-family: 'MyFont_SansBol';
src: url('/assets/fonts/MyFontSansBol.ttf') format('truetype');
src: url('/assets/fonts/MyFontSansBol.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSansBol.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSansBol.woff') format('woff'); /* Pretty Modern Browsers */
}
#font-face {
font-family: 'MyFont_SansLig';
src: url('/assets/fonts/MyFontSansLig.ttf') format('truetype');
src: url('/assets/fonts/MyFontSansLig.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSansLig.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSansLig.woff') format('woff'); /* Pretty Modern Browsers */
}
#font-face {
font-family: 'MyFont_SansDem';
src: url('/assets/fonts/MyFontSansDem.ttf') format('truetype');
src: url('/assets/fonts/MyFontSansDem.eot'); /* IE9 Compat Modes */
src: url('/assets/fonts/MyFontSansDem.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('/assets/fonts/MyFontSansDem.woff') format('woff'); /* Pretty Modern Browsers */
}
body {
font-family: 'MyFont_SansLig';
}
h2 {
font-family: 'MyFont_SerifReg';
font-size: 40px !important;
}
h4 {
font-family: 'MyFont_SansBol';
line-height:1.5em;
}
p {
font-family: 'MyFont_SansLig';
font-size:16px;
}
b {
font-family: 'MyFont_SerifReg';
font-size:18px;
}
And I have no problem to load the fonts while visiting the website via We
EDIT:
A screen from the Console, Looks like the "fonts" folder is not loaded in "Sources"
Console
The problem appears only when I try to load the website in Local: the font's are not loaded.
What am I writing wrong?
It might be because the path problem.
Try to use relative path (assume the assets folder is at the same place as the html): ../assets/fonts/MyFontSerifReg.ttf
#font-face {
font-family: 'MyFont_SerifReg';
src: url('/assets/fonts/MyFontSerifReg.ttf') format('truetype'),
url('/assets/fonts/MyFontSerifReg.woff') format('woff');
}
Please make sure to cross-check below trouble shooting guide:
path provided in url()
Apply Style as below for example:
body{
font-family: 'MyFont_SerifReg'; // Same name defined in rule
}
Add reference of your CSS file where rules are defined in HTML.
Related
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.
This question already has answers here:
How to add some non-standard font to a website?
(21 answers)
Closed 5 years ago.
I found the most beautiful font here. I want to use it. I tried following:
#font-face {
font-family: myFirstFont;
src: url(http://fontsforweb.com/font/show/?id=78041);
}
div {
font-family: myFirstFont;
}
(Source: https://www.w3schools.com/css/css3_fonts.asp)
That is not source for font its just website where you can download it. Download font and place in folder fonts then change your code src to that path.
Download the full zip file, Extract it then put it in your project then use this code:
#font-face {
font-family: myFirstFont;
src: url(MonsieurPomme.woff);
}
div {
font-family: myFirstFont;
}
You need to download the font files and add links to the various formats, depending on which browsers you want to support:
#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 */
}
See https://css-tricks.com/snippets/css/using-font-face/ for more info.
Using font-face.
#font-face{
font-family: ((fontName));
src: url(fontname.woff);
}
Then you can call it just as how you call other fonts.
You need to directly link to the font file instead of just the webpage.
#font-face {
font-family: myFont;
src: url('font.eot'); /* IE9 Compatible Modes */
src: url('font.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('font.woff2') format('woff2'), /* Super Modern Browsers */
url('font.woff') format('woff'), /* Pretty Modern Browsers */
url('font.ttf') format('truetype'), /* Safari, Android, iOS */
url('font.svg#svgFontName') format('svg'); /* Legacy iOS */
}
div {
font-family: 'myFont', serif;
}
On a website that I'm developing I am able to import and display via #font-face my custom font.
It works perfectly on different browsers
In the specific what I did was:
#font-face {
font-family: 'MyCustomFont';
src: url('assets/fonts/MyCustomFont.eot'); /* IE9 Compat Modes */
src: url('assets/fonts/MyCustomFont.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('assets/fonts/MyCustomFont.woff') format('woff'); /* Pretty Modern Browsers */
}
body {
font-family: 'MyCustomFont', sans-serif;
}
The problem is that when I try to import the .ttf and .svg formats the font is not displayed anymore and the Fallback font will be applied.
This is how I imported .svg and .ttf
#font-face {
font-family: 'MyCustomFont';
src: url('assets/fonts/MyCustomFont.eot'); /* IE9 Compat Modes */
src: url('assets/fonts/MyCustomFont.eot?#iefix') format('embedded-opentype'); /* IE6-IE8 */
src: url('assets/fonts/MyCustomFont.woff') format('woff'); /* Pretty Modern Browsers */
src: url('assets/fonts/MyCustomFont.ttf') format('truetype'); /* Safari, Android, iOS */
src: url('assets/fonts/MyCustomFont.svg#svgMyCustomFont') format('svg'); /* Legacy iOS */
}
body {
font-family: 'MyCustomFont', sans-serif;
}
How come is this happening?
Is possible to fix it?
Thanks in advance
Put a comma at the end of each line instead of a ";" and only define the source once.
#font-face {
font-family: 'MyCustomFont';
src: url('assets/fonts/MyCustomFont.eot'), /* IE9 Compat Modes */
url('assets/fonts/MyCustomFont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('assets/fonts/MyCustomFont.woff') format('woff'), /* Pretty Modern Browsers */
url('assets/fonts/MyCustomFont.ttf') format('truetype'), /* Safari, Android, iOS */
url('assets/fonts/MyCustomFont.svg#svgMyCustomFont') format('svg'); /* Legacy iOS */
}
I am trying to load a custom font from my server but it's not retrieving the font
I am using the following code, can some body tell me the one which i'm using is in correct format.
Code :
#font-face {
font-family: trcustomfont ;
src: url( http://content.sales-accredit.com/BTGOV/Fonts/Knowledge-Regular.otf ) format("opentype");
}
.customfont {
font-family: trcustomfont;
}
You should write 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.woff') format('woff'), /* Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
Or Read More About how to use custom fonts for our websites.....
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