Gone through some other threads regarding a similar problem, but their solution didn't work. I had been successfully using the code below to add a font to our site which was based off a comprehensive bootstrap template. I now started work on a new site, this time from only a base bootstrap template and tried to add fonts via the same method.
#font-face {
font-family: 'myfontname';
src: url('font/myfontname-Regular.svg');
src: url('font/myfontname-Regular.eot');
src: url('font/myfontname-Regular.eot?#iefix') format('embedded-opentype'),
url('font/myfontname-Regular.woff2') format('woff2'),
url('font/myfontname-Regular.woff') format('woff'),
url('font/myfontname-Regular.ttf') format('truetype')
}
#font-face {
font-family: 'myfontname';
font-weight: bold;
src: url('font/myfontname-Bold.svg');
src: url('font/myfontname-Bold.eot');
src: url('font/myfontname-Bold.eot?#iefix') format('embedded-opentype'),
url('font/myfontname-Bold.woff2') format('woff2'),
url('font/myfontname-Bold.woff') format('woff'),
url('font/myfontname-Bold.ttf') format('truetype')
}
.myfontnameBOLD{
font-family: myfontname;
font-weight: bold;
text-transform: uppercase;
}
.myfontnameREG{
font-family: myfontname;
}
Files are all stored in the same manner as previous ( a Font folder within my css folder). However this time I get the following error
uncaught syntaxError:Invalid or unexpected token
In Chrome the debug highlights the very first line where it says "#font-face"
I ran this through a Linter and no problem, but even I.E is giving an error and highlighting #font-face and saying it has a missing semi-colon.
Anyone able to see what might be wrong? thanks
ok I found the answer and it was a silly one. thanks for your replies. the problem was the actually declaration of the css file in my HTML. I had put it in <script> tags by mistake instead of <link>. slaps self
Could it be the missing semi-colon after url('font/myfontname-Regular.ttf') format('truetype') and url('font/myfontname-Bold.ttf') format('truetype') ?
#font-face {
font-family: 'myfontname';
src: url('font/myfontname-Regular.svg');
src: url('font/myfontname-Regular.eot');
src: url('font/myfontname-Regular.eot?#iefix') format('embedded-opentype'),
url('font/myfontname-Regular.woff2') format('woff2'),
url('font/myfontname-Regular.woff') format('woff'),
url('font/myfontname-Regular.ttf') format('truetype');
}
#font-face {
font-family: 'myfontname';
font-weight: bold;
src: url('font/myfontname-Bold.svg');
src: url('font/myfontname-Bold.eot');
src: url('font/myfontname-Bold.eot?#iefix') format('embedded-opentype'),
url('font/myfontname-Bold.woff2') format('woff2'),
url('font/myfontname-Bold.woff') format('woff'),
url('font/myfontname-Bold.ttf') format('truetype');
}
I've added the semi-colon
I believe that Ayush's answer may solve your problem! I would also like to add that the order in which the fonts are loaded may create some problems in some browsers and platforms. The order in which the src element is read varies depending on what browser and version are using it. Take the example below from CSS-Tricks,
#font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compatible 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 */
}
It's best to include SVG last because it might be picked up by some browsers (like the modern ones) where woff or woff2 is supported.
Related
I have 4 Fonts I need to use on a website and i have there files in my website folder
Baskerville.ttc
BellGothicstd-Black.otf
BellGothicstd-Bold.otf
JennaSue.ttf
I have tried to Import the using #Import and The fonts still do not work here is what I used:
#import url(../fonts/BellGothicStd-Black.otf);
#import url(../fonts/BellGothicStd-Bold.otf);
#import url(../fonts/Baskerville.ttc);
#import url(../fonts/JennaSue.ttf);
I also tried to use the #font-face Rule this is what I used:
#font-face {
font-family: 'BellGothicBlack';
src: url('../fonts/BellGothic-Black.otf') format('OpenType'),
}
#font-face {
font-family: 'BellGothicBold';
src: url('../fonts/BellGothicStd-Bold.otf') format('OpenType'),
}
#font-face {
font-family: 'Baskerville';
src: url('../fonts/Baskerville.ttc') format('OpenType'),
}
#font-face {
font-family: 'JennaSue';
src: url('../fonts/JennaSue.ttf') format('TrueType'),
}
Could someone tell me what I'm doing wrong? I think I might be missing some code I'm not really sure.
Thanks in Advance
Tom
You will need to convert the font into the correct formats for all browsers to display them.. (check rights before you do this)
http://www.fontsquirrel.com/tools/webfont-generator
Your #font-face rule will also need to include all the font types...
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 */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
U need to generate font-faceto all the fonts for OS and Browser compatibility.
Font-face generator URL:http://www.fontsquirrel.com/tools/webfont-generator
#font-face {
font-family: 'Helvetica';
src: url('helvetica.eot');
src: url('helvetica.eot?iefix') format('eot'),
url('helvetica.woff') format('woff'),
url('helvetica.ttf') format('truetype'),
url('helvetica.svg#helvetica') format('svg');
font-weight: normal;
font-style: normal;
}
I'm using #font-face in my project for loading a specific webfont ("Amsi Pro"). The main problem is that it works on most of the computers I tested, but not on all (On those where it didn't work other websites with #font-face still worked).
Is there anything I've missed, or any server settings to set that will give me full support?
Some information of a PC where #font-face doesn't work:
whatsmybrowser.org/b/Q2TJ80F
Live Preview:
christlicher-gesundheitskongress.de
CSS:
#font-face {
font-family: 'AmsiPro';
font-weight: 400;
src: url('../webfonts/2E508B_0_0.eot');
src: url('../webfonts/2E508B_0_0.eot?#iefix') format('embedded-opentype'),
url('../webfonts/2E508B_0_0.woff2') format('woff2'),
url('../webfonts/2E508B_0_0.woff') format('woff'),
url('../webfonts/2E508B_0_0.ttf') format('truetype');
}
#font-face {
font-family: 'AmsiPro';
font-weight: 600;
src: url('../webfonts/2E508B_1_0.eot');
src: url('../webfonts/2E508B_1_0.eot?#iefix') format('embedded-opentype'),
url('../webfonts/2E508B_1_0.woff2') format('woff2'),
url('../webfonts/2E508B_1_0.woff') format('woff'),
url('../webfonts/2E508B_1_0.ttf') format('truetype');
}
html,body {
font-family: 'AmsiPro', Helvetica, sans-serif;
}
Even though it seems that Firefox 38 should support #font-face, there may be a partial use issue. Try using an app like Font-Squirrel to develop an SVG of your font and then reorder your #font-face like so:
#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 */
}
Per this source, it should maximize the amount of support your font has.
Hope this helped!
I am using Lato fonts in my website,Mozilla and chrome are not rendering the font when i referred the fonts from fonts folder , then after I have used embedded woff inside the css files which is working fine but the css files have become large sizes.
My question is ,Why the font is not working good when i am referring from external folder,but the same is working fine when i am embedding inside the css?
/* Webfont: ../fonts/Lato-Regular */#font-face {
font-family: 'Lato-Regular';
src: url('../fonts/Lato-Regular.eot'); /* IE9 Compat Modes */
src: url('../fonts/Lato-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../fonts/Lato-Regular.woff') format('woff'), /* Modern Browsers */
url('../fonts/Lato-Regular.ttf') format('truetype');
font-style: normal;
font-weight: normal;
text-rendering: optimizeLegibility;
}
Remove text-rendering and check the same
Update :
Try this
#font-face{font-family:'Lato-Regular';
src: url('../Lato-Regular.eot');
src: url('../Lato-Regular.eot?#iefix') format('embedded-opentype'),
url('../Lato-Regular.woff') format('woff'),
url('../Lato-Regular.ttf') format('truetype'),
url('../Lato-Regular.svg#Lato-Regular') format('svg');
font-weight:normal;
font-style:normal;
}
I'm having a hard time making a font look properly in the major browsers (I'm only using the Windows versions BTW for now, don't have access to Mac), I'll try to mention the code and how it behaves with each change I did to the SVG line because that's what most people suggest changing after doing some research about similar issues.
#font-face {
font-family: 'RobotoLight';
src: url('../font/jura-demibold.eot');
src: url('../font/jura-demibold.eot?#iefix') format('embedded-opentype'),
url('../font/jura-demibold.woff') format('woff'),
url('../font/jura-demibold.ttf') format('truetype'),
url('../font/jura-demibold.svg#RobotoLight') format('svg');
font-weight: normal;
font-style: normal; }
This code makes the font look very pixelated in:
Google Chrome and Safari
However it looks fine in FireFox and IE.
This is the 2nd code (I bumped up the SVG line):
#font-face {
font-family: 'RobotoLight';
src: url('../font/jura-demibold.eot');
src: url('../font/jura-demibold.eot?#iefix') format('embedded-opentype'),
url('../font/jura-demibold.svg#RobotoLight') format('svg');
url('../font/jura-demibold.woff') format('woff'),
url('../font/jura-demibold.ttf') format('truetype'),
font-weight: normal;
font-style: normal; }
Font isn't even displayed anymore and is replaced by a default webfont in:
FireFox, Chrome and Safari
Still looks normal in IE.
Finally, when I remove the "#RobotoLight" from the SVG line, like this:
#font-face {
font-family: 'RobotoLight';
src: url('../font/jura-demibold.eot');
src: url('../font/jura-demibold.eot?#iefix') format('embedded-opentype'),
url('../font/jura-demibold.svg') format('svg');
url('../font/jura-demibold.woff') format('woff'),
url('../font/jura-demibold.ttf') format('truetype'),
font-weight: normal;
font-style: normal; }
Font still isn't displayed in FireFox, but it now works properly (without Pixelation) in Chrome, Safari and IE!
So can someone help me make the 3rd code work with FireFox as well please, cross browser font compatibility is driving me insane.
ps: I'm not an experienced developer and still new to this, I bought a ready template that I'm trying to change some stuff in it to create a basic website for myself, I'm not sure if this matters but I didn't change the font-family name in the CSS sheet, I added the fonts in the proper folder and edited the SRC URL to the right path.
I assume the font-family name is for my own reference in the CSS sheet and browsers don't actually verify it.
Any help would be MUCH appreciated!
You have a comma and a semicolon mixed up. The correct block would be:
#font-face {
font-family: 'RobotoLight';
src: url('../font/jura-demibold.eot');
src: url('../font/jura-demibold.eot?#iefix') format('embedded-opentype'),
url('../font/jura-demibold.svg') format('svg'),
url('../font/jura-demibold.woff') format('woff'),
url('../font/jura-demibold.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
change
url('../font/jura-demibold.svg') format('svg');
to
url('../font/jura-demibold.svg') format('svg'),
EDIT: These little mistakes happen to the best of us.
The webpage where I'm trying to get the custom font "Duke-Fill" to display is http://www.hamlinforcongress.com/helpout.php
I'm using:
#font-face {
font-family: 'header_font';
src: url('Duke-Fill.eot?#iefix') format('embedded-opentype'),
url('Duke-Fill.woff') format('woff'),
url('Duke-Fill.ttf') format('truetype'),
url('Duke-Fill.svg#svgFontName') format('svg');
}
.header_font{
font-family: header_font;
}
I've tried every other suggestion I can find on the Internet, but nothing can make the custom font display in Internet Explorer. It works perfectly in every other conceivable browser, but not IE (surprise surprise). Help?
#font-face {
font-family: 'NimbusSanConD-Lig';
src: url('fonts/228BFB_1_0.eot');
src: url('fonts/228BFB_1_0.eot?#iefix') format('embedded-opentype'),
url('fonts/228BFB_0_0.woff') format('woff'),
url('fonts/228BFB_0_0.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
This code works in IE. It was generated using Font Squirrel