#font-face - Custom font not displayed after importing .ttf and .svg - css

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 */
}

Related

How to use a custom font in CSS? [duplicate]

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;
}

Downloaded font won't display properly

I downloaded a font and in my CSS I have :
#font-face {
font-family: "Gotham Medium";
src: url("Gotham/Gotham-Medium.otf");}
When I call say in
h1 { font-family:'Gotham Medium'}
the font display does not match what Gotham should look like. Nor is it a default font.
Is the problem a matter of something being changed when downloaded in my laptop ?
The font is not in the google API so I can't try with an external link.
Your Css should be 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.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 */
}
css Trick
To do this you can use a generator for font-face but you must have the license for the web font

#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";
}

Why #font-face does not work in my web application?

I used #font-face in my Web Application like this :
#font-face {
font-family: BKoodak;
src: url('../Content/Styles/ThirdParties/Fonts/BKoodakBold.eot'); /* IE9 Compatibility Modes */
src: url('../Content/Styles/ThirdParties/Fonts/BKoodakBold.eot?') format('eot'), /* IE6-IE8 */
url('../Content/Styles/ThirdParties/Fonts/BKoodakBold.woff') format('woff'), /* Modern Browsers */
url('../Content/Styles/ThirdParties/Fonts/BKoodakBold.ttf') format('truetype'); /* Safari, Android, iOS */
}
and then using it like this :
body {
line-height: 1;
font-family:BKoodak
}
what is the problem?
EDIT:In network tab(Chrome) i filter font but i find out that the browser don't get the font at all !! and in console i didn't get any 404 error!! i confused! what's wrong?
Are you sure about your file address ?
you could use this code and change file address
#font-face {
font-family: 'BKoodakBold';
src: url('fonts/BKoodakBold.eot?#') format('eot'), /* IE6–8 */
url('fonts/BKoodakBold.woff') format('woff'), /* FF3.6+, IE9, Chrome6+, Saf5.1+*/
url('fonts/BKoodakBold.ttf') format('truetype'); /* Saf3—5, Chrome4+, FF3.5, Opera 10+ */
}

#font face is not working

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.....

Resources