Reputation: 723
I'm building a new WordPress theme (don't know if that's relevant) and there's this issue that keeps bugging me.
I've loaded up Roboto Slab from Google Webfonts (included the CSS in <head>
section). On every other browser out there, font is rendered OK, except Google Chrome. When I first load up the website in Google Chrome, texts using that custom font are NOT displayed AT ALL (even tho font-stack has Georgia as a fallback - "Roboto Slab", Georgia, serif;
). After I hover the styled link, or retrigger any CSS property in Inspector - texts become visible.
Since I've started the theme some time ago, I can clearly remember that it was working perfectly before. Is this some known recent Chrome update bug?
First load:
After I reapply any of the CSS properties, get into responsive view or hover an element:
Anyone have similar issues? How should I proceed with this?
Thanks!
Upvotes: 72
Views: 118663
Reputation: 1623
I'm just sharing what worked for me. Your results may vary.
I had main.css
with an @import
of multiple fonts, separated by a |
(pipe) character. This had been working up until today. I kept all of my Google Font imports in the main CSS file because I didn't have that many. Today I added one that simply wouldn't render, either in Chrome or Firefox. I tried a different font - same problem.
Finally, I made a separate @import
in another CSS file that gets loaded for several pages on the site (let's call it navbar_pages.css
, for example) - this CSS gets included in the relevant pages via <link rel="stylesheet" type="text/css" href="/css/navbar_pages.css">
, just like main.css
does.
For some reason, having the @import in a separate CSS file solved the problem.
I suspect it is due to a limit on the number of fonts that can be called in a single @import
call. More testing should be done to pin down the cause, but for now there is my workaround. If anyone has insights, please chime in with a comment.
Upvotes: 0
Reputation:
If anyone is still struggling with this issue (2019), there seems to be a bug in Google Fonts CSS generator script.
I loaded my fonts with the following tag:
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:400,300">
Every @font-face
in the file contained a line like this:
src: local('Roboto'), local('Roboto-Regular'), local('sans-serif'), url(https://fonts.gstatic.com/s/roboto/v19/KFOmCnqEu92Fr1Mu4mxKKTU1Kg.woff2) format('woff2');
As you can see, the local('sans-serif')
is placed prior to the remote URL, which is wrong. This causes Chrome to load the default sans-serif font instead of the requested one.
A simple fix is to reorder the font-weight
part of the URL, from Roboto:400,300
to Roboto:300,400
. This causes the generator to not include the local('sans-serif')
source.
Hope it helps someone.
Upvotes: 0
Reputation: 942
See similar problem in question Strange Issue while Google Font Rendering.
Solution is in loading the desired font (I my case 'Fira Sans') from the Mozilla CDN instead of Google CDN.
Upvotes: 1
Reputation: 766
It's possible that the element has text-rendering: optimizeLegibility
set which can cause this, or similar, issues. Changing it to auto
fixed this problem for me with a Foundation 5 project that sets it to optimizeLegibility
by default.
Upvotes: 0
Reputation: 7004
In case the first rated post is not working, here is a solution:
remove the 'http:' in:
<link href='http://fonts.googleapis.com/css?family=Alfa+Slab+One' rel='stylesheet' type='text/css'>
or
@import url(http://fonts.googleapis.com/css?family=Alfa+Slab+One);
As explained by David Bain, most modern browsers don't actually require that you specify the protocol, they will "deduce" the protocol based on the context from which you called it
Upvotes: 12
Reputation: 373
I was trying to work with Meg's answer,but like many others it didn't work for me either.
For using Google Font,found this trick[Adding Screenshots for steps].
1) Just take the url from the css or standard link as highlighted.
2) Open the link in another tab, copy whole css code(i.e. font-face) in your css file and run.
Not sure about performance as many http calls are getting added, or just try copying one font-face.
Upvotes: 0
Reputation: 29
i just used to delete roboto font from my windows fonts and every thing work right now.
it is maybe beacause you have older version of font on your system . i guess .
Upvotes: 0
Reputation: 1008
I just faced the same issue. I it was due to HTTP/S protocol mismatch as described here.
Use https version of URL.
Upvotes: 1
Reputation: 291
It is not a actual solution but it works better for me than everything else in this thread. I changed the font. I had Fira Sans and now just changed to Roboto which works out of the box.
Upvotes: 0
Reputation: 983
If people are still having this problem before you try all the great solutions on here try using an !important tag in your css to see if that will fix it, as it did for me and I am not sure if the bug is the same as the old Chrome bug.
.faultyText {"Roboto Slab", Georgia, serif !important}
Upvotes: -1
Reputation: 595
Checkout plugin I made: https://chrome.google.com/webstore/detail/fontfix/ekgfbmjaehhpbakdbpfmlepngjkaalok
It does the web realign with pure javascript, which force browser to redraw whole page.
Upvotes: -3
Reputation: 99
It may not be a silver bullet, but fixe the issue on our site by moving the fontawesome css link to the bottom of our pages as well as weblike fix listed above.
Upvotes: -1
Reputation: 375
Tried the css fix alone above with no success. Finally resolved by creating a style sheet (chrome.css) containing:
body {
-webkit-animation-delay: 0.1s;
-webkit-animation-name: fontfix;
-webkit-animation-duration: 0.1s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: linear;
}
@@-webkit-keyframes fontfix {
from { opacity: 1; }
to { opacity: 1; }
}
And loading it with jquery at the bottom of the page:
<script type="text/javascript">
$(document).ready(function () {
$('head').append('<link href="/chrome.css" rel="stylesheet" />');
});
</script>
Upvotes: 7
Reputation: 11
I got it fixed with the JS solution, but also needed to use the latest google hosted jquery (1.11) to get it fixed.
Upvotes: 1
Reputation: 4976
The CSS fix didn't work for me, also the 0.5 sec delay script seems awkward.
This JS snippet seems to work for us:
<script type="text/javascript">
jQuery(function($) {
if (/chrom(e|ium)/.test(navigator.userAgent.toLowerCase())) {
$('body').css('opacity', '1.0')
}
})
</script>
Upvotes: 9
Reputation: 21
I've incorporated the above CSS ... but I ALSO am including the following javascript in my header:
(Note, I know I haven't customized the fonts in the code below. But regardless, it still seems to help in forcing Chrome to repaint the fonts on the page ... just make sure your fonts are properly referenced elsewhere)
With the CSS mentioned above used in conjunction with the below code included in my ... at worst, all fonts on my page will show up after a second or so of delay.
Hope this helps people. Cheers.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(function() { $('body').hide().show(); });
</script>
<script type="text/javascript">
//JavaScript goes here
WebFontConfig = {
google: { families: ['FontOne', 'FontTwo'] },
fontinactive: function (fontFamily, fontDescription) {
//Something went wrong! Let's load our local fonts.
WebFontConfig = {
custom: { families: ['FontOne', 'FontTwo'],
urls: ['font-one.css', 'font-two.css']
}
};
loadFonts();
}
};
function loadFonts() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
}
(function () {
//Once document is ready, load the fonts.
loadFonts();
})();
</script>
Here's where I found the above: https://productforums.google.com/forum/#!topic/chrome/tYHSqc-fqso
Upvotes: 2
Reputation: 1472
Apparently it's a known Chrome bug. There's a css-only workaround that should solve the problem:
body {
-webkit-animation-delay: 0.1s;
-webkit-animation-name: fontfix;
-webkit-animation-duration: 0.1s;
-webkit-animation-iteration-count: 1;
-webkit-animation-timing-function: linear;
}
@-webkit-keyframes fontfix {
from { opacity: 1; }
to { opacity: 1; }
}
It seems like Chrome just needs to be told to repaint the text
Upvotes: 90