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: a screenshot #1
After I reapply any of the CSS properties, get into responsive view or hover an element: a screenshot #2
Anyone have similar issues? How should I proceed with this?
Thanks!
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
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>
If the css fix does not work for you
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
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>
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
I got it fixed with the JS solution, but also needed to use the latest google hosted jquery (1.11) to get it fixed.
I just faced the same issue. I it was due to HTTP/S protocol mismatch as described here.
Use https version of URL.
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.
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.
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 .
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.
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.
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.
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.
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}
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.
来源:https://stackoverflow.com/questions/22011139/google-fonts-are-not-rendering-on-google-chrome