Webfont using #font-face stopped working - css

Ive been using webfonts on my website, using #font-face and it stopped working after some browser updates, now it doesnt really work on Chrome or Firefox (the two main browsers my users use).
I tried a couple of different things but none of them made it work again. Does anyone have any idea of what could have happened?
My website is http://goronah.blog.br/
The link for the CSS is: http://www.goronah.blog.br/wp-content/themes/goronahresponsive/style.css
The #font-face is:
#font-face{
font-family:Bebas Neue;
src: url('BebasNeue.otf');
font-style:normal;
font-weight:normal;
}
and a common use:
h2 {
font-size:2.4em;
font-family:"Bebas Neue";
font-weight:normal;
}

Chrome DevTools shows the following error regarding the font:
Font from origin 'http://www.goronah.blog.br' has been blocked from
loading by Cross-Origin Resource Sharing policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://goronah.blog.br' is therefore not allowed
access.
Basically due to security reasons the browser won't download the font as it comes from another (sub)domain www.goronah.blog.br than your site goronah.blog.br. I noticed that the first simply redirects to the latter, so I assume it's simply an alias and all content is available from both url's.
The easiest way to solve this is to remove the www. part from the link to your stylesheet.
<link rel="stylesheet" type="text/css" href="http://www.goronah.blog.br/wp-content/themes/goronahresponsive/style.css" />
into
<link rel="stylesheet" type="text/css" href="http://goronah.blog.br/wp-content/themes/goronahresponsive/style.css" />

To make sure you cover all browsers with your font, you need to specifiy different font-types.
You need a:
WOFF or WOFF2 (Woff2 had better rendering)
SVG
EOT
TTF or OTF
To generate these fonts, you can use a webfont-generator like http://www.fontsquirrel.com/tools/webfont-generator.
If you have all the required font-types, you can include them like this (see comments in code for broswer support):
#font-face {
font-family: 'Bebas Neue';
src: url('BebasNeue.eot'); /* IE9 Compat Modes */
src: url('BebasNeue.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('BebasNeue.woff2') format('woff2'), /* Super Modern Browsers */
url('BebasNeue.woff') format('woff'), /* Pretty Modern Browsers */
url('BebasNeue.ttf') format('truetype'), /* Safari, Android, iOS */
url('BebasNeue.svg#svgFontName') format('svg'); /* Legacy iOS */
font-style:normal;
font-weight:normal;
}

Related

Adding custom font to laravel Applications

So, I am confused by this:
#font-face {
font-family:'rift';
src: url('../vendor/fonts/Fort Foundry - Rift-Bold.otf') format('otf');
font-style: 'normal';
font-weight: '700';
}
It lives in public/vendor/fonts/ and whats confusing is that unless I physically install the font - the font doesn't render properly.
I thought the whole aspect of using custom fonts was that the end user did not have to have them installed on their machine, that it should just work. Am I missing something when it comes to using custom fonts in css?
I get no errors in the console with or with out the font installed. Is there a way to verify that it is actually working? Or is that why we have things like fallbacks?
.site-name{
color: #fff;
font-size: 22px;
font-family: rift, sans-serif; // Fallbacks
}
Can some one explain the concept of using custom fonts and if I am setting it up properly in css? From a Laravel perspective.
You can host the font files on your server, to make use of a custom font on your site. Visitors are not required to have the font installed on their machine.
Make sure to choose a file name without spaces and special chars. You'll need to offer different formats of the font (like .eot, .woff2,...) to make it work across the different browsers and operating systems. Otherwise, the fallback font (in your case sans-serif) will be used.
Check out the article Using #font-face on CSS-Tricks. This is how your CSS could look like:
#font-face {
font-family: 'rift';
font-style: 'normal';
font-weight: '700';
src: url('../vendor/fonts/fort-foundry.eot'); /* IE9 Compat Modes */
src: url('../vendor/fonts/fort-foundry.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../vendor/fonts/fort-foundry.woff2') format('woff2'), /* Super Modern Browsers */
url('../vendor/fonts/fort-foundry.woff') format('woff'), /* Pretty Modern Browsers */
url('../vendor/fonts/fort-foundry.ttf') format('truetype'), /* Safari, Android, iOS */
url('../vendor/fonts/fort-foundry.svg#FortFoundry') format('svg'); /* Legacy iOS */
}
Troubleshooting
Visit your site and open the Developer Tools. Go to the tab Console.
Reload the page and look out for errors to make sure that the path to your font files is correct. If it's not, there will be an error 404 visible in the logs.

Use different font in internet explorer only

I am having a real serious trouble using custom face in internet explorer.
I am using a specific font now, with font-face, and it working perfectly fine in modern browser, but i just cannot get it to work in IE.
The method I am using the font in Chrome, Firefox, etc. is the following:
font-family: xy;
src: url(fonts/xy.otf);
}
Is there a way that IE use another font?
font-family: xy, iefont, sans; is not working, because font-typed is specified in a lot of css, and places,
* {font-family: xy, iefont, sans !important} is not working becasue it drops the "FontAwesome" family specified earlier.
What is the simpliest to format every text but only for IE?
IE specific CSS
For browser specific css files I would recommend:
Simple solution, just use this JS library and you can easily apply styles for every browser/os combination:
BrowserClass.js
With this you will get a class name on the body tag with the current name and version of the browser also with the used OS.
After include the file:
<script src="js/browserclass.js"></script>
For example on Windows 8.1 with the latest ie you will see:
<body class="ie ie11 win desktop">
And in your style file you can refer by:
(.sass styling)
body.ie
+declare-font-face('Open Sans Light', 'OpenSans-Light-webfont', 200)
Note:
Conditional Comments in IE only work for up to IE9!
SASS mixin
Or If u are using SASS, here's a good mixin:
// ---------------------
// Font Face Mixin
// ---------------------
=declare-font-face($font-family, $font-filename, $font-weight: normal, $font-style: normal, $font-stretch: normal)
#font-face
font-family: #{$font-family}
src: url("../fonts/#{$font-filename}.eot")
src: url("../fonts/#{$font-filename}.eot?#iefix") format("embedded-opentype"), url("../fonts/#{$font-filename}.svg##{$font-family}") format("svg"), url("../fonts/#{$font-filename}.woff") format("woff"), url("../fonts/#{$font-filename}.ttf") format("truetype")
font-weight: $font-weight
font-style: $font-style
font-stretch: $font-stretch
Usage:
+declare-font-face('Open Sans Light', 'OpenSans-Light-webfont', 200)
Internet explorer uses .eot font files. You can make this work even in IE8. You need to convert your otf fonts to woff, eot, ...
#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 */
}
You can use http://www.fontsquirrel.com/ for example to generate these files.
You can make use of Conditional Comments in IE.
<!--[if IE]>
<style>
.myfontclass {
//your IE specific font here
}
</style>
<![endif]-->
Hope that helps!

Data URI in embedded font declaration (#font-face) breaks IE < 9

I have a CSS file with a #font-face declaration that embeds the font file via a data URI:
#font-face {
font-family: 'Custom-Font';
src: url('eot/font.eot');
src: url('eot/font.eot?#iefix') format('embedded-opentype'),
/* ugly FF same-Origin workaround... */
url("data:application/octet-stream;base64,d09GRgABAAAAA ... ") format('woff'),
url('ttf/font.ttf') format('truetype'),
url('svg/font.svg#Custom-Font') format('svg');
}
Embedding the font with the data URI causes IE < 9 to not load the font. If I remove the line (or change it back to reference the .woff file), IE will load the font.
What about this CSS confuses IE?
Background: I have a page which loads embedded fonts from a different domain (a CDN). Unfortunately, Mozilla requires a CORS header (Access-Control-Allow-Origin) on embedded fonts served from different domains (an abuse of CORS and terrible idea in my opinion). For reasons beyond my control (bureaucracy), I'm unable to get the CORS header sent out on font files, so I'm stuck with the sub-optimal situation of embedding the font file in the CSS file via a data URI.
I had the same problem. Moving the embedded font into a different declaration worked for me.
#font-face {
/* Non-FF */
font-family: 'Custom-Font';
src: url('eot/font.eot');
src: url('eot/font.eot?#iefix') format('embedded-opentype'),
url('svg/font.svg#Custom-Font') format('svg');
}
#font-face {
/* FF same-Origin workaround... */
font-family: 'Custom-Font';
src: url(data:font/truetype;charset=utf-8;base64,d09GRgABAAAAA...) format('truetype');
}
The maximum URL length has probably been exceeded.
Remember that older versions of IE adds everything between the ? and the last '); (including the data URI).
So in your case the solution would be to use another method (Mo' Bulletproofer for example).

font-face in Internet Explorer

I'm sure I'm not the only one that this has plagued, but I can't seem to find a solution.
#font-face works wonderfully in Firefox, Chrome, Safari with TTF fonts.
as so:
#font-face{
font-family: "Apple-Chancery" ;
src: url(images/Apple-Chancery.ttf ) format("truetype");
}
However, I understand that to be used in Microsoft, the font has to be in EOT format, so I converted it using http://ttf2eot.sebastiankippe.com/
And my code looks like this:
#font-face{
font-family: "Apple-Chancery" ;
src: local("Apple Chancery"), url(images/Apple-Chancery.eot), url(images/Apple-Chancery.ttf ) format("truetype"); /* non-IE */
}
but it's not working in Internet Explorer. I've tried putting two difference lines for src: I've tried using a different converter, different font, and all no go. I'm using IE8.
Also, to use multiple custom fonts, do I need multiple #font-face blocks or I use line them up font-family, src, font-family, src, etc.?
How about using font squirrel to generate all your files and your code?
This may help you,
#font-face {
font-family:"Apple-Chancery";
src: url('../font/Apple-Chancery.eot'); /* IE9 Compat Modes */
src: url('../font/Apple-Chancery.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('../font/Apple-Chancery.woff') format('woff'), /* Modern Browsers */
url('../font/Apple-Chancery.ttf') format('truetype'), /* Safari, Android, iOS */
url('../font/Apple-Chancery.svg#svgFontName') format('svg'); /* Legacy iOS */
font-weight:bold;
font-style:normal;
}
This page may be useful to you: http://msdn.microsoft.com/en-us/library/ms530757%28VS.85%29.aspx
In particular, this line:
In Internet Explorer 8 and earlier versions, only one URL value is supported.
I think what you're trying to do may not work right until IE9 is available. It'd be worth getting a copy of the beta (assuming you're running something newer than Windows XP) to test and confirm this.
You need to put the IE (eot) one on a separate line, before the other ones.
The correct declaration is:
#font-face{
font-family: "Apple-Chancery" ;
src: url(images/Apple-Chancery.eot); /* IE */
src: local("Apple Chancery"), url(images/Apple-Chancery.ttf ) format("truetype"); /* non-IE */
}
But that's probably not enough to cover all the cases, you're missing svg font type for older chromes, etc.. I'd recommend using the font-face generator from fontsquirel.com, choose the Easy option then check out the generate css file and copy/paste the code and converted font files
I second the use of Font Squirrel.
You could also take a look at my post Adventures with #font-face which might help you.
Simpy upload your font on font2web it creates a css file and a demo HTML file.
Hope this help you

How to make Google Fonts work in IE?

I've been developing a site that uses the Google Fonts API. It's great, and supposedly has been tested in IE, but when testing in IE 8 the fonts simply don't get styled.
I included the font, as Google instructs, thus:
<link href="http://fonts.googleapis.com/css?family=Josefin+Sans+Std+Light"
rel="stylesheet" type="text/css" />
and added its name to the front of a font family in CSS thus:
body {
font-family: "Josefin Sans Std Light", "Times New Roman", Times, serif;
font-size: 16px;
overflow-y: scroll;
overflow-x: hidden;
color: #05121F;
}
Works like a charm in Chrome, Firefox, Safari. No dice in IE 8. Anybody know why?
Looks like IE8-IE7 can't understand multiple Google Web Font styles through the same file request using the link tags href.
These two links helped me figure this out:
See this open Google issue, and look at the comments.
Also see this StackOverlow Answer Google Web Fonts don't work in
IE8
The only way I have gotten it to work in IE7-IE8 is to only have one Google Web Font request. And only have one font style in the href of the link tag:
So normally you would have this, declaring multiple font styles in the same request:
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,300,800,700,400italic" />
But in IE7-IE8 add a IE conditional and specify each Google font style separately and it will work:
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:700" />
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:800" />
<![endif]-->
Hope this can help others!
The method, as indicated by their technical considerations page, is correct - so you're definitely not doing anything wrong. However, this bug report on Google Code indicate that there is a problem with the fonts Google produced for this, specifically the IE version. This only seems to affect only some fonts, but it's a real bummmer.
The answers on the thread indicate that the problem lies with the files Google's serving up, so there's nothing you can do about it. The author suggest getting the fonts from alternative locations, like FontSquirrel, and serving it locally instead, in which case you might also be interested in sites like the League of Movable Type.
N.B. As of Oct 2010 the issue is reported as fixed and closed on the Google Code bug report.
Google Fonts uses Web Open Font Format (WOFF), which is good, because it's the recommended font format by the W3C.
IE versions older than IE9 don't support Web Open Font Format (WOFF) because it didn't exist back then. To support < IE9, you need to serve your font in Embedded Open Type (EOT). To do this you will need to write your own #font-face css tag instead of using the embed script from Google. Also you need to convert the original WOFF file to EOT.
You can convert your WOFF to EOT over here by first converting it to TTF and then to EOT:
http://convertfonts.com/
Then you can serve the EOT font like this:
#font-face {
font-family: 'MyFont';
src: url('myfont.eot');
}
Now it works in < IE9. However, modern browsers don't support EOT anymore, so now your fonts won't work in modern browsers. So you need to specify them both. The src property supports this by comma seperating the font urls and specefying the type:
src: url('myfont.woff') format('woff'),
url('myfont.eot') format('embedded-opentype');
However, < IE9 doesn't understand this, it just graps the text between the first quote and the last quote, so it will actually get:
myfont.woff') format('woff'),
url('myfont.eot') format('embedded-opentype
as the URL to the font. We can fix this by first specifying a src with only one url which is the EOT format, then specifying a second src property that's meant for the modern browsers and < IE9 will not understand. Because < IE9 will not understand it it will ignore the tag so the EOT will still be working. The modern browsers will use the last specified font they support, so probably WOFF.
src: url('myfont.eot');
src: url('myfont.woff') format('woff');
So only because in the second src property you specify the format('woff'), < IE9 won't understand it (or actually it just can't find the font at the url myfont.woff') format('woff) and will keep using the first specified one (eot).
So now you got your Google Webfonts working for < IE9 and modern browsers!
For more information about different font type and browser support, read this perfect article by Alex Tatiyants:
http://tatiyants.com/how-to-get-ie8-to-support-html5-tags-and-web-fonts/
While Yi Jiang's solution may work, I don't believe abandoning the Google Web Font API is the right answer here. We serve a local jQuery file when it's not properly loaded from the CDN, right?
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/js/jquery-1.9.0.min.js"><\/script>')</script>
So why wouldn't we do the same for fonts, specifically for < IE9?
<link href='http://fonts.googleapis.com/css?family=Cardo:400,400italic,700' rel='stylesheet' type='text/css'>
<!--[if lt IE 9]><link href='/css/fonts.css' rel='stylesheet' type='text/css'><![endif]-->
Here's my process when using custom fonts:
Download the font's ZIP folder from Google, and use Font Squirrel's
#font-face Generator to create the local web font.
Create a fonts.css file that calls the newly created, locally hosted font files (only linking to the file if < IE9, as shown above). NOTE: The #font-face Generator creates this file for you.
#font-face {
font-family: 'cardoitalic';
src: url('cardo-italic-webfont.eot');
src: url('cardo-italic-webfont.eot?#iefix') format('embedded-opentype'),
url('cardo-italic-webfont.woff') format('woff'),
url('cardo-italic-webfont.ttf') format('truetype'),
url('cardo-italic-webfont.svg#cardoitalic') format('svg');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'cardobold';
src: url('cardo-bold-webfont.eot');
src: url('cardo-bold-webfont.eot?#iefix') format('embedded-opentype'),
url('cardo-bold-webfont.woff') format('woff'),
url('cardo-bold-webfont.ttf') format('truetype'),
url('cardo-bold-webfont.svg#cardobold') format('svg');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'cardoregular';
src: url('cardo-regular-webfont.eot');
src: url('cardo-regular-webfont.eot?#iefix') format('embedded-opentype'),
url('cardo-regular-webfont.woff') format('woff'),
url('cardo-regular-webfont.ttf') format('truetype'),
url('cardo-regular-webfont.svg#cardoregular') format('svg');
font-weight: normal;
font-style: normal;
}
Using IE conditional classes in your main stylesheet to avoide faux weights and styles, your font styles might look like this:
h1{
font-size:3.25em;
font-weight:normal;
font-style:italic;
font-family:'Cardo','cardoitalic',serif;
line-height:1.25em;
}
h2{
font-size:2.75em;
font-weight:700;
font-family:'Cardo','cardobold',serif;
line-height:1.25em;
}
strong
,b{
font-family:'Cardo','cardobold',serif;
font-weight:700,
}
.lt-ie9 h1{
font-style:normal;
}
.lt-ie9 h2{
font-weight:normal;
}
.lt-ie9 strong,
.lt-ie9 b{
font-weight:normal,
}
Sure, it's a little extra work, but haven't we come to expect this from IE? Besides, it becomes second-nature after awhile.
For what its worth, I couldn't get it working on IE7/8/9 and the multiple declaration option didn't make any difference.
The fix for me was as a result of the instructions on the Technical Considerations Page where it highlights...
For best display in IE, make the stylesheet 'link' tag the first
element in the HTML 'head' section.
Works across IE7/8/9 for me now.
I tried all the options from above and they didn't work.
Then I located the google font (Over the Rainbow) in my folder (new) and used IE conditional below and it worked perfect.
<!--[if IE]>
<style type="text/css">
#font-face {
font-family: "Over the Rainbow";
src: url("../new/over.ttf");
src: local("Over the Rainbow"), url("../new/over.ttf");
}
</style>
<![endif]-->
I hope it will help
You can try fontsforweb.com where fonts are working for all browsers, because they are provided in TTF, WOFF and EOT formats together with CSS code ready to be pasted on your page i.e.
#font-face{
font-family: "gothambold1";
src: url('http://fontsforweb.com/public/fonts/5903/gothambold1.eot');
src: local("Gotham-Bold"), url('http://fontsforweb.com/public/fonts/5903/gothambold1.woff') format("woff"), url('http://fontsforweb.com/public/fonts/5903/gothambold1.ttf') format("truetype");
}
.fontsforweb_fontid_5903 {
font-family: "gothambold1";
}
or you can download them zipped in a package with CSS file attached
then just add class to any element to apply that font i.e.
<h2 class="fontsforweb_fontid_5903">This will be written with Gotham Bold font and will work in all browsers</h2>
See it working: http://jsfiddle.net/SD4MP/
It's all about trying all those answers, for me, nothing works except the next solution:
Google font suggested
#import 'https://fonts.googleapis.com/css?family=Assistant';
But, I'm using here foreign language fonts, and it didn't work on IE11 only. I found out this solution that worked:
#import 'https://fonts.googleapis.com/css?family=Assistant&subset=hebrew';
Hope that save someone precious time
Try this type of link , it will run in also IE . hope this helps .
<link href='//fonts.googleapis.com/css?family=Josefin+Sans:300,400,600,700,300italic' rel='stylesheet' type='text/css'>
I had the same problem with you.
I found a solution using a Adobe Web Fonts code, work perfect in Internet Explorer, Chrome, Firefox and Safari.
More info in this page: http://html.adobe.com/edge/webfonts/
After my investigation, I came up to this solution:
//writing the below line into the top of my style.css file
#import url('https://fonts.googleapis.com/css?family=Assistant:200,300,400,600,700,800&subset=hebrew');
MUST OBSERVE:
We must need to write the font-weight correctly of this font. For example: font-weight:900; will not work as we have not included 900 like 200,300,400,600,700,800 into the URL address while importing from Google with the above link. We can add or include 900 to the above URL, but that will work only if the above Google Font has this option while embedding.

Resources